//static readonly ILog _log = LogManager.GetLogger(typeof(INIClassGenerator)); //if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } //if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } public static void CreateClass(string INIFile, string NameSpace, string ClassName, string targetPath) { INIContainer container = new INIContainer(INIFile); ClassGenerator cg = new ClassGenerator(NameSpace, ClassName, true, string.Empty, "[INIConversion(\"{0}\")]"); StringBuilder sb = new StringBuilder(); sb.AppendLine(cg.GetClassPrefix(string.Empty, "ChangeDependencyObject")); foreach (INIKeyValueItem item in container.Values.Values) { string propertyName = item.Key.Substring(0, 1).ToUpperInvariant() + item.Key.Substring(1); double val = double.NaN; string type = "string"; if (double.TryParse(item.Value, out val)) { type = "double"; } sb.AppendLine(cg.GetDependencyProperty(propertyName, type, item.Key)); } sb.AppendLine(cg.GetClassSuffix()); using (StreamWriter sw = new StreamWriter(targetPath)) { sw.Write(sb.ToString()); } }
void ProcessNode(XmlNode node) { //produces one class, to be saved. StringBuilder sb = new StringBuilder(); string className = GetClassName(node.Name); bool addedHere = false; bool PossibleCollection = false; if (!ClassesCreated.Contains(className)) { ClassesCreated.Add(className); addedHere = true; if (node.NextSibling != null) { PossibleCollection = (node.NextSibling.Name == node.Name); } } ClassGenerator cg = new ClassGenerator("~~~~~~", className, true, "[XmlConversionRoot(\"{0}\")]", "[XmlConversion(\"{0}\")]"); sb.Append(cg.GetClassPrefix(node.Name, DependencyObjectString)); string PropertyName = null; string TypeName = null; if (node.Attributes != null) { foreach (XmlAttribute attrib in node.Attributes) { PropertyName = GetClassName(attrib.Name); TypeName = "string"; //if (PossibleCollection) //{ // if (CreateDependencyObjects) // { // TypeName = "ObservableCollection<" + PropertyName + ">"; // } // else // { // TypeName = "List<" + PropertyName + ">"; // } // PropertyName = PropertyName + "Group"; //} if (CreateDependencyObjects) { sb.AppendLine(cg.GetDependencyProperty(PropertyName, TypeName, attrib.Name)); } else { sb.AppendLine(cg.GetProperty(PropertyName, TypeName, attrib.Name)); } } } if (node.ChildNodes != null) { string LastNodeName = string.Empty; foreach (XmlNode nd in node.ChildNodes) { if (nd.Name != LastNodeName) { bool isCollection = false; if (nd.NextSibling != null) { isCollection = (nd.NextSibling.Name == nd.Name); } TypeName = GetClassName(nd.Name); PropertyName = TypeName + "Object"; if (isCollection) { PropertyName = TypeName + "Group"; if (CreateDependencyObjects) { TypeName = "ObservableCollection<" + TypeName + ">"; } else { TypeName = "List<" + TypeName + ">"; } } if (CreateDependencyObjects) { sb.AppendLine(cg.GetDependencyProperty(PropertyName, TypeName, nd.Name)); } else { sb.AppendLine(cg.GetProperty(PropertyName, TypeName, nd.Name)); } ProcessNode(nd); LastNodeName = nd.Name; } } } sb.AppendLine(cg.GetClassSuffix()); if (addedHere) { if (File.Exists(className + ".cs")) { File.Delete(className + ".cs"); } using (StreamWriter sw = new StreamWriter(Path.Combine(TargetDirectoryPath, className + ".cs"))) { sw.WriteLine(sb.ToString()); } } }