示例#1
0
 void AddAttributes(ClassInfo classInfo, XmlSchemaObjectCollection attributes)
 {
     foreach (XmlSchemaAttribute attribute in attributes)
     {
         classInfo.Attributes.Add(PropertyFromAttribute(classInfo, attribute));
     }
 }
示例#2
0
 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());
     }
 }
示例#3
0
        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());
            }
        }
示例#4
0
 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";
     }
 }
示例#5
0
 private void CleanUnknownClasses(ClassInfo classInfo)
 {
     foreach (var property in classInfo.Elements.Where(property => !_classes.ContainsKey(property.XmlType)))
     {
         property.XmlType = property.IsParsable
             ? property.XmlType
             : "string";
     }
 }
示例#6
0
 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);
     }
 }
示例#7
0
        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());
        }
示例#8
0
 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;
     }
 }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        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);
                }
            }
        }
示例#12
0
 private void WriteAutoProperties(ClassInfo classInfo)
 {
     foreach (var property in classInfo.AllMembers)
         _writer.WriteLine("\t\tpublic virtual {0} {1} {{ get; set; }}", property.GetCodeType(), property.GetCodeName());
 }
示例#13
0
 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());
 }
示例#14
0
 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");
 }
示例#15
0
        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();
        }
示例#16
0
        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);
            }
        }
示例#17
0
 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}");
 }
示例#18
0
        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);
        }
示例#19
0
 void WriteConstructors(ClassInfo classInfo)
 {
     WriteXElementConstructor(classInfo, _writer);
     _writer.WriteLine();
     WriteEmptyConstructor(classInfo);
 }
示例#20
0
 private void WriteConstructors(ClassInfo classInfo)
 {
     WriteXElementConstructor(classInfo, _writer);
     _writer.WriteLine();
     WriteEmptyConstructor(classInfo);
 }
示例#21
0
        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;
        }
示例#22
0
        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);
        }
示例#23
0
 private PropertyInfo PropertyFromAttribute(ClassInfo classInfo, XmlSchemaAttribute attribute)
 {
     var prop = new PropertyInfo(classInfo)
     {
         XmlName = attribute.Name,
         XmlType = ResolveSimpleTypeName(attribute.SchemaTypeName.Name)
     };
     return prop;
 }
示例#24
0
 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;
 }
示例#25
0
 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);
 }
示例#26
0
 public PropertyInfo(ClassInfo targetClass)
 {
     _targetClass = targetClass;
 }
示例#27
0
 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"));
     }
 }
示例#28
0
 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);
 }
示例#29
0
 public void Write(ClassInfo classInfo)
 {
     WriteOriginalClass(classInfo);
     WriteNullClass(classInfo);
 }
示例#30
0
        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);
        }
示例#31
0
 private void WriteEmptyConstructor(ClassInfo classInfo)
 {
     _writer.WriteLine("\t\tpublic {0}(){1}\t\t{{ }}", classInfo.GetCodeName(), Environment.NewLine);
 }
示例#32
0
 PropertyInfo PropertyFromAttribute(ClassInfo classInfo, XmlSchemaAttribute attribute)
 {
     var prop = new PropertyInfo(classInfo){XmlName = attribute.Name, XmlType = "string"};
     TrySettingElementType(attribute.SchemaType, attribute.SchemaTypeName, prop);
     return prop;
 }
示例#33
0
 void WriteEmptyConstructor(ClassInfo classInfo)
 {
     _writer.WriteLine("\t\tpublic {0}(){1}\t\t{{ }}", classInfo.GetCodeName(), Environment.NewLine);
 }
示例#34
0
 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}");
 }
示例#35
0
 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();
 }
示例#36
0
 public void Write(ClassInfo classInfo)
 {
     WriteOriginalClass(classInfo);
     WriteNullClass(classInfo);
 }