void AddAttributes(ClassInfo classInfo, XmlSchemaObjectCollection attributes) { foreach (XmlSchemaAttribute attribute in attributes) { classInfo.Attributes.Add(PropertyFromAttribute(classInfo, attribute)); } }
void GenerateThrowingProperties(ClassInfo classInfo) { foreach (PropertyInfo property in classInfo.Elements.Union(classInfo.Attributes)) { _writer.WriteLine("\t\tpublic override {0} {1} {{ get {{ throw this.NullAccess(\"{1}\"); }} }}", property.GetCodeType(), property.GetCodeName()); } }
void WriteAutoProperties(ClassInfo classInfo) { foreach (var property in classInfo.Elements.Union(classInfo.Attributes)) { if (property.IsElementValue) WriteImplicitStringCast(classInfo); _writer.WriteLine("\t\tpublic virtual {0} {1} {{ get; set; }}", property.GetCodeType(), property.GetCodeName()); } }
private void CleanUnknownClasses(ClassInfo classInfo, IDictionary<string, ClassInfo> classes) { foreach (var property in classInfo.AllMembers.Where(property => !classes.ContainsKey(property.XmlType))) { property.XmlType = property.IsParsable ? property.XmlType : "string"; } }
private void CleanUnknownClasses(ClassInfo classInfo) { foreach (var property in classInfo.Elements.Where(property => !_classes.ContainsKey(property.XmlType))) { property.XmlType = property.IsParsable ? property.XmlType : "string"; } }
private void GenerateUniquePropertyNames(ClassInfo classInfo) { var attributesToRename = classInfo.Attributes.Where(attribute => classInfo.Elements.Any(p => p.XmlName == attribute.XmlName)).ToList(); foreach (var attribute in attributesToRename) { classInfo.Attributes.Remove(attribute); attribute.XmlName += "Attribute"; classInfo.Attributes.Add(attribute); } }
void WriteEqualityMembers(ClassInfo classInfo) { _writer.WriteLine( @" public static bool operator ==({0} left, {0} right) {{ return Utils.ValidatedEquals<Null{0}>(left, right); }} public static bool operator !=({0} left, {0} right) {{ return !(left == right); }}", classInfo.GetCodeName()); }
private void RenameClassIfNecesarry(ClassInfo classInfo, List<ClassInfo> existingClasses) { int suffix = 0; while (true) { if (!existingClasses.Any(c => (c.XmlName == classInfo.XmlName) && (c.NameSuffix == suffix))) { classInfo.NameSuffix = suffix; return; } ++suffix; } }
private void AddValueProperty(ClassInfo classInfo, XmlSchemaSimpleContentExtension sce) { var propInfo = new PropertyInfo(classInfo) { IsList = false, XmlName = "Value", XmlType = ResolveSimpleTypeName(sce.BaseTypeName.Name), IsElementValue = true }; if (!classInfo.Elements.Contains(propInfo)) classInfo.Elements.Add(propInfo); }
private void AddExtensionAttributes(ClassInfo classInfo, XmlSchemaComplexType complex) { if (complex.ContentModel == null || !(complex.ContentModel.Content is XmlSchemaSimpleContentExtension)) return; var sce = complex.ContentModel.Content as XmlSchemaSimpleContentExtension; if (sce.Attributes.Count == 0) return; AddAttributes(classInfo, sce.Attributes); AddValueProperty(classInfo, sce); }
void AddExtensionAttributes(ClassInfo classInfo, XmlSchemaComplexType complex) { if (complex.ContentModel != null && complex.ContentModel.Content is XmlSchemaSimpleContentExtension) { var sce = complex.ContentModel.Content as XmlSchemaSimpleContentExtension; if (sce.Attributes.Count > 0) { AddAttributes(classInfo, sce.Attributes); var propInfo = new PropertyInfo(classInfo) { IsList = false, XmlName = "Value", XmlType = "Value", IsElementValue = true }; if (!classInfo.Elements.Contains(propInfo)) classInfo.Elements.Add(propInfo); } } }
private void WriteAutoProperties(ClassInfo classInfo) { foreach (var property in classInfo.AllMembers) _writer.WriteLine("\t\tpublic virtual {0} {1} {{ get; set; }}", property.GetCodeType(), property.GetCodeName()); }
private void WriteThrowingProperties(ClassInfo classInfo) { foreach (PropertyInfo property in classInfo.AllMembers) _writer.WriteLine("\t\tpublic override {0} {1} {{ get {{ throw this.NullAccess(\"{1}\"); }} }}", property.GetCodeType(), property.GetCodeName()); }
private void WritePropertyInitializationStatements(ClassInfo classInfo, StreamWriter writer) { foreach (PropertyInfo property in classInfo.Elements) WritePropertyInitialization(writer, property, "Elements"); foreach (PropertyInfo property in classInfo.Attributes) WritePropertyInitialization(writer, property, "Attributes"); }
private void WriteImplicitStringCast(ClassInfo classInfo) { if (!classInfo.AllMembers.Any(m => m.IsElementValue && m.GetCodeType() == "string")) return; _writer.WriteLine("\t\tpublic override string ToString(){return Value;}"); _writer.WriteLine("\t\tpublic static implicit operator string(" + classInfo.GetCodeName() + " obj){return obj.Value;}"); _writer.WriteLine(); }
private void ParseParticle(ClassInfo classInfo, XmlSchemaParticle particle, string nsCode) { var group = particle as XmlSchemaGroupBase; if (group == null) return; bool isList = (group.MaxOccurs > 1); foreach (XmlSchemaParticle groupMember in group.Items) { if (groupMember is XmlSchemaElement) ParseElementProperty(classInfo, (XmlSchemaElement)groupMember, (groupMember.MaxOccurs > 1) || isList, nsCode); else ParseParticle(classInfo, groupMember, nsCode); } }
void WriteXElementConstructor(ClassInfo classInfo, StreamWriter writer) { writer.WriteLine("\t\tpublic {0}(XElement element){1}\t\t{{", classInfo.GetCodeName(), Environment.NewLine); WritePropertyInitialisationStatements(classInfo, writer); writer.WriteLine("\t\t}"); }
void WriteOriginalClass(ClassInfo classInfo) { _writer.WriteLine("\tpublic partial class {0}{1}\t{{", classInfo.GetCodeName(), Environment.NewLine); WriteAutoProperties(classInfo); _writer.WriteLine(); WriteConstructors(classInfo); _writer.WriteLine(); WriteEqualityMembers(classInfo); _writer.WriteLine("\t}}{0}", Environment.NewLine); }
void WriteConstructors(ClassInfo classInfo) { WriteXElementConstructor(classInfo, _writer); _writer.WriteLine(); WriteEmptyConstructor(classInfo); }
private void WriteConstructors(ClassInfo classInfo) { WriteXElementConstructor(classInfo, _writer); _writer.WriteLine(); WriteEmptyConstructor(classInfo); }
private ClassInfo ParseComplex(XmlSchemaComplexType complex, string name, string nsCode) { var classInfo = new ClassInfo { XmlName = name }; ParseParticle(classInfo, complex.Particle, nsCode); if (complex.Attributes.Count > 0) AddAttributes(classInfo, complex.Attributes); AddExtensionAttributes(classInfo, complex); GenerateUniquePropertyNames(classInfo); return classInfo; }
private void GenerateComplex(ClassInfo classInfo, XmlSchemaComplexType complex, string nsCode) { GenerateParticle(classInfo, complex.Particle, nsCode); if (complex.Attributes.Count > 0) AddAttributes(classInfo, complex.Attributes); AddExtensionAttributes(classInfo, complex); }
private PropertyInfo PropertyFromAttribute(ClassInfo classInfo, XmlSchemaAttribute attribute) { var prop = new PropertyInfo(classInfo) { XmlName = attribute.Name, XmlType = ResolveSimpleTypeName(attribute.SchemaTypeName.Name) }; return prop; }
private bool Equals(ClassInfo other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Equals(other.XmlName, XmlName) && Equals(other.Elements, Elements) && other.NameSuffix == NameSuffix; }
void WriteNullClass(ClassInfo classInfo) { _writer.WriteLine("\tinternal class Null{0} : {0}{1}\t{{", classInfo.GetCodeName(), Environment.NewLine); GenerateThrowingProperties(classInfo); _writer.WriteLine("\t}}{0}", Environment.NewLine); }
public PropertyInfo(ClassInfo targetClass) { _targetClass = targetClass; }
void WritePropertyInitialisationStatements(ClassInfo classInfo, StreamWriter writer) { foreach (PropertyInfo property in classInfo.Elements) { writer.WriteLine(property.InitialiseFromCollection("Elements")); } foreach (PropertyInfo property in classInfo.Attributes) { writer.WriteLine(property.InitialiseFromCollection("Attributes")); } }
private void WriteNullClass(ClassInfo classInfo) { _writer.WriteLine("\tinternal class Null{0} : {0}{1}\t{{", classInfo.GetCodeName(), Environment.NewLine); WriteThrowingProperties(classInfo); _writer.WriteLine("\t}}{0}", Environment.NewLine); }
public void Write(ClassInfo classInfo) { WriteOriginalClass(classInfo); WriteNullClass(classInfo); }
private void ParseElementProperty(ClassInfo classInfo, XmlSchemaElement elem, bool isList, string nsCode) { var propInfo = new PropertyInfo(classInfo) { IsList = isList, XmlName = elem.Name, XmlType = ResolveTypeName(elem, nsCode) }; ParseElement(elem, nsCode); if (!classInfo.Elements.Contains(propInfo)) classInfo.Elements.Add(propInfo); }
private void WriteEmptyConstructor(ClassInfo classInfo) { _writer.WriteLine("\t\tpublic {0}(){1}\t\t{{ }}", classInfo.GetCodeName(), Environment.NewLine); }
PropertyInfo PropertyFromAttribute(ClassInfo classInfo, XmlSchemaAttribute attribute) { var prop = new PropertyInfo(classInfo){XmlName = attribute.Name, XmlType = "string"}; TrySettingElementType(attribute.SchemaType, attribute.SchemaTypeName, prop); return prop; }
void WriteEmptyConstructor(ClassInfo classInfo) { _writer.WriteLine("\t\tpublic {0}(){1}\t\t{{ }}", classInfo.GetCodeName(), Environment.NewLine); }
private void WriteXElementConstructor(ClassInfo classInfo, StreamWriter writer) { writer.WriteLine("\t\tpublic {0}(XElement element){1}\t\t{{", classInfo.GetCodeName(), Environment.NewLine); WritePropertyInitializationStatements(classInfo, writer); writer.WriteLine("\t\t}"); }
void WriteImplicitStringCast(ClassInfo classInfo) { _writer.WriteLine("\t\tpublic override string ToString(){return Value;}"); _writer.WriteLine("\t\tpublic static implicit operator string(" + classInfo.GetCodeName() + " obj){return obj.Value;}"); _writer.WriteLine(); }