Example #1
0
        public override void WriteTo(XmlWriter writer)
        {
            XmlTemplateWriter xmlTemplateWriter = (XmlTemplateWriter)writer;
            object            value             = xmlTemplateWriter.ReplacementSet.ReplacementEntries[token];

            if (value is string stringValue)
            {
                writer.WriteRaw(stringValue);
            }
            else if (value is IEnumerable <string> valueSet)
            {
                foreach (string item in valueSet)
                {
                    writer.WriteRaw(item);
                }
            }
            else if (value is DelimitedStringSet delimitedStringSet)
            {
                bool firstWritten = false;
                foreach (string item in delimitedStringSet.Items)
                {
                    if (firstWritten)
                    {
                        writer.WriteRaw(delimitedStringSet.Delimiter);
                    }

                    writer.WriteRaw(item);
                    firstWritten = true;
                }
            }
            else
            {
                throw new InvalidCastException($"Can't treat {value} as string or IEnumerable<string>");
            }
        }
 public void Write(XmlTemplateWriter xmlTemplateWriter)
 {
     foreach (KeyValuePair <string, ITemplateToken> pair in Tokens)
     {
         pair.Value.PrepareForReplacement(xmlTemplateWriter.ReplacementSet);
     }
     element.WriteTo(xmlTemplateWriter);
 }
 public override void Write(string path, TemplateReplacementSet replacementSet)
 {
     using (StreamWriter writer = new StreamWriter(path))
         using (XmlTemplateWriter xmlWriter = new XmlTemplateWriter(writer, replacementSet))
         {
             rootPart.Write(xmlWriter);
         }
 }
        public override void WriteTo(XmlWriter writer)
        {
            XmlTemplateWriter      parentWriter         = ((XmlTemplateWriter)writer);
            TemplateReplacementSet parentReplacementSet = parentWriter.ReplacementSet;

            // Don't dispose
            if (parentReplacementSet.ReplacementEntries.TryGetValue(token, out object value))
            {
                List <TemplateReplacementSet> replacementSets = (List <TemplateReplacementSet>)value;
                foreach (TemplateReplacementSet replacementSet in replacementSets)
                {
                    parentWriter.ReplacementSet = replacementSet;
                    Write(parentWriter);
                }
            }
            parentWriter.ReplacementSet = parentReplacementSet;
        }