Exemple #1
0
        private static string Expansion(string format, XmlNode node, Parameters parameters, Strings templates, StringsStack expansionsStack)
        {
            var name = node.LocalName;

            if (name != ValueName)
            {
                if (Accept(node, parameters))
                {
                    var template        = GetTemplate(format, name, templates);
                    var isValueTemplate = template.Contains(VariableNameValue);
                    var expansions      = new Strings {
                        { VariableNameValue, "" }
                    };
                    expansionsStack.Push(expansions);
                    foreach (var currentFormat in GetFormats(GetVariables(template), format))
                    {
                        AddExpansions(currentFormat, node.ChildNodes, isValueTemplate, expansions, parameters, templates, expansionsStack);
                        AddExpansions(currentFormat, node.Attributes, false, expansions, parameters, templates, expansionsStack);
                    }
                    var result = expansionsStack.GetActiveValues().Aggregate(template, (current, currentExpansion) => current.Replace(currentExpansion.Key, currentExpansion.Value));
                    expansionsStack.Pop();
                    return(result);
                }
                return("");
            }
            return(CleanValue(node.Value, true));
        }
Exemple #2
0
 private static void AddExpansions(string format, IEnumerable nodes, bool isValueTemplate, Strings expansions, Parameters parameters, Strings templates, StringsStack stringsStack)
 {
     if (nodes != null)
     {
         foreach (XmlNode currentChild in nodes)
         {
             var currentExpansion = Expansion(format, currentChild, parameters, templates, stringsStack);
             var currentKey       = isValueTemplate ? VariableNameValue : DelimiterVariable + format + SeparatorFormat + currentChild.LocalName + DelimiterVariable;
             AddExpansion(expansions, currentKey, currentExpansion, parameters);
         }
     }
 }