using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace UniversalEditor { public class ExpandedString { public static readonly ExpandedString Empty = new ExpandedString(); public ExpandedString() { } public ExpandedString(params ExpandedStringSegment[] segments) { foreach (ExpandedStringSegment segment in segments) { mvarSegments.Add(segment); } } private ExpandedStringSegment.ExpandedStringSegmentCollection mvarSegments = new ExpandedStringSegment.ExpandedStringSegmentCollection(); public ExpandedStringSegment.ExpandedStringSegmentCollection Segments { get { return mvarSegments; } } public override string ToString() { StringBuilder sb = new StringBuilder(); foreach (ExpandedStringSegment segment in mvarSegments) { sb.Append(segment.ToString()); } return sb.ToString(); } } public abstract class ExpandedStringSegment { public class ExpandedStringSegmentCollection : System.Collections.ObjectModel.Collection { } private static readonly Dictionary _empty = new Dictionary(); public abstract string ToString(Dictionary variables); public override string ToString() { return ToString(_empty); } } public class ExpandedStringSegmentLiteral : ExpandedStringSegment { private string mvarValue = String.Empty; public string Value { get { return mvarValue; } set { mvarValue = value; } } public override string ToString(Dictionary variables) { return mvarValue; } } /// /// Represents a string segment whose value is populated by a variable. /// public class ExpandedStringSegmentVariable : ExpandedStringSegment { private string mvarVariableName = String.Empty; /// /// The name of the variable in the variables dictionary from which to retrieve the value for this . /// public string VariableName { get { return mvarVariableName; } set { mvarVariableName = value; } } /// /// Creates a new instance of with the given variable name. /// /// The name of the variable in the variables dictionary from which to retrieve the value for this . public ExpandedStringSegmentVariable(string variableName) { mvarVariableName = variableName; } /// /// Returns the value of this with the given variables. /// /// The variables to pass into the . /// A that contains the value of this . public override string ToString(Dictionary variables) { return variables[mvarVariableName]; } } }