예제 #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);
 }