Ejemplo n.º 1
0
        /// <summary>
        /// Loads from an <see cref="XElement"/>.
        /// </summary>
        private static void Load(CodeGenerator codeGen, CodeGenConfig config, XElement xml, Dictionary <string, string> parameters = null)
        {
            // Add a SysId with a GUID for global uniqueness.
            config.AttributeAdd("SysId", Guid.NewGuid().ToString());

            // Load the attributes.
            foreach (XAttribute xa in xml.Attributes())
            {
                if (xa.Value != null)
                {
                    config.AttributeUpdate(xa.Name.LocalName, xa.Value);
                }
            }

            // Update/override the attribues with the parameters.
            if (config.Parent == null && parameters != null)
            {
                foreach (KeyValuePair <string, string> kvp in parameters)
                {
                    config.AttributeUpdate(kvp.Key, kvp.Value);
                }
            }

            // Before children load.
            if (codeGen.Loaders.ContainsKey(config.Name))
            {
                codeGen.Loaders[config.Name].LoadBeforeChildren(config);
            }

            // Load the children.
            foreach (XElement xmlChild in xml.Nodes().Where(x => x.NodeType == XmlNodeType.Element || x.NodeType == XmlNodeType.CDATA))
            {
                // Load CDATA nodes separately.
                if (xmlChild.NodeType == XmlNodeType.CDATA)
                {
                    config.CDATA = xmlChild.Value;
                    continue;
                }
                else if (xmlChild.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                CodeGenConfig child = new CodeGenConfig(xmlChild.Name.LocalName, config);
                Load(codeGen, child, xmlChild);

                if (!config.Children.ContainsKey(child.Name))
                {
                    config.Children.Add(child.Name, new List <CodeGenConfig>());
                }

                config.Children[child.Name].Add(child);
            }

            // After children load.
            if (codeGen.Loaders.ContainsKey(config.Name))
            {
                codeGen.Loaders[config.Name].LoadAfterChildren(config);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the config value for a specified parameter.
        /// </summary>
        private void SetConfigValue(string name, CodeGenConfig config, string value)
        {
            CodeGenConfig val  = GetConfig(name, config, out string propertyName);
            var           oval = GetValue(value, config);
            string        sval = (oval == null) ? null : ((oval is bool) ? ((bool)oval ? "true" : "false") : oval.ToString());

            val.AttributeUpdate(propertyName, TemplateReplace(sval, config));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Update the Count and Index attributes.
 /// </summary>
 internal static void UpdateCountAndIndex(CodeGenConfig config)
 {
     // Update the Count and Index attributes.
     foreach (KeyValuePair <string, List <CodeGenConfig> > kvp in config.Children)
     {
         config.AttributeUpdate($"{kvp.Key}Count", kvp.Value.Count.ToString(CultureInfo.InvariantCulture));
         int index = 0;
         foreach (CodeGenConfig child in kvp.Value)
         {
             child.AttributeUpdate($"{child.Name}Index", index++.ToString(CultureInfo.InvariantCulture));
             UpdateCountAndIndex(child);
         }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Update the Count and Index attributes.
 /// </summary>
 internal static void UpdateCountAndIndex(CodeGenConfig config)
 {
     // Update the Count and Index attributes.
     foreach (KeyValuePair <string, List <CodeGenConfig> > kvp in config.Children)
     {
         config.AttributeUpdate(string.Format("{0}Count", kvp.Key), kvp.Value.Count.ToString());
         int index = 0;
         foreach (CodeGenConfig child in kvp.Value)
         {
             child.AttributeUpdate(string.Format("{0}Index", child.Name), index++.ToString());
             UpdateCountAndIndex(child);
         }
     }
 }