private void BuildConstructorList(string defaultValue, string fixedValue, bool required, decimal maxOccurs, string fieldName, string clrTypeName, string elmtAtrrName, ArrayList ctorList, bool isEnum) { ClassConstructor constructor = new ClassConstructor(); if ((defaultValue != null) || (fixedValue != null)) { constructor.required = true; if (maxOccurs > 1M) { constructor.defaultValue = elmtAtrrName; constructor.fieldName = fieldName; if (clrTypeName == "System.String") { constructor.datatype = CtorDatatypeContext.PropertyCollectionString; } else { constructor.datatype = CtorDatatypeContext.PropertyCollection; } } else if (isEnum) { constructor.defaultValue = (defaultValue != null) ? defaultValue : fixedValue; constructor.defaultValue = clrTypeName + "." + constructor.defaultValue; constructor.fieldName = fieldName; constructor.datatype = CtorDatatypeContext.ValueTypeDefault; } else if (this.code.IsValueType(clrTypeName)) { constructor.defaultValue = (defaultValue != null) ? defaultValue : fixedValue; constructor.fieldName = fieldName; constructor.datatype = CtorDatatypeContext.ValueTypeDefault; } else if (clrTypeName == "System.String") { constructor.defaultValue = (defaultValue != null) ? defaultValue : fixedValue; constructor.fieldName = fieldName; constructor.datatype = CtorDatatypeContext.String; } ctorList.Add(constructor); } else { constructor.required = required; if (maxOccurs > 1M) { constructor.defaultValue = elmtAtrrName; constructor.fieldName = fieldName; if (clrTypeName == "System.String") { constructor.datatype = CtorDatatypeContext.PropertyCollectionString; } else { constructor.datatype = CtorDatatypeContext.PropertyCollection; } } else { constructor.defaultValue = ""; constructor.fieldName = fieldName; if (isEnum) { constructor.datatype = CtorDatatypeContext.ValueType; } else if (clrTypeName == "System.DateTime") { constructor.datatype = CtorDatatypeContext.DateTime; } else if (this.code.IsValueType(clrTypeName)) { constructor.datatype = CtorDatatypeContext.ValueType; } else if (clrTypeName == "System.String") { constructor.datatype = CtorDatatypeContext.String; } else { constructor.datatype = CtorDatatypeContext.Other; } } ctorList.Add(constructor); } }
private void ParseGroupBasePass2(XmlSchemaGroupBase groupBase, string className, ArrayList ctorList, ArrayList childClasses, ArrayList parentClassStack, Hashtable dotnetFieldList, string parentNamespace, Hashtable classReferencesAdded) { if (classReferencesAdded == null) { classReferencesAdded = new Hashtable(); } for (int i = 0; i < groupBase.Items.Count; i++) { decimal maxOccurs = groupBase.MaxOccurs; if (groupBase.Items[i] is XmlSchemaElement) { XmlSchemaElement elementRef = (XmlSchemaElement) groupBase.Items[i]; XmlSchemaElement element = (XmlSchemaElement) this.schema.Elements[elementRef.QualifiedName]; if (element == null) { element = elementRef; } maxOccurs = (elementRef.MaxOccurs > maxOccurs) ? elementRef.MaxOccurs : maxOccurs; string nameSpace = (element.QualifiedName.Namespace != "") ? element.QualifiedName.Namespace : parentNamespace; if ((element.ElementType is XmlSchemaComplexType) && (element.SchemaTypeName.Namespace != "http://www.w3.org/2001/XMLSchema")) { string dotnetClassName = ""; XmlSchemaComplexType elementType = (XmlSchemaComplexType) element.ElementType; if (!classReferencesAdded.ContainsKey(element.Name)) { classReferencesAdded.Add(element.Name, element.Name); if ((element == elementRef) && (this.schema.SchemaTypes[elementType.QualifiedName] == null)) { string str3 = ""; foreach (string str4 in parentClassStack) { str3 = str3 + str4; } dotnetClassName = (string) this.globalQualifiedComplexTypeClasses[element.QualifiedName + str3]; childClasses.Add(new ChildComplexType(elementType, element.Name, dotnetClassName, nameSpace, element.QualifiedName)); dotnetClassName = LanguageBase.ReplaceInvalidChars(dotnetClassName); this.code.ClassComplexTypeFieldCode(this.outStream, element.Name, dotnetClassName, dotnetClassName, className, maxOccurs, 1M, this.elementFormDefault, nameSpace, element.IsNillable, false); } else { string str5 = ""; if (((elementType.QualifiedName.Name == null) || (elementType.QualifiedName.Name == "")) && ((elementRef.QualifiedName.Name != null) && (elementRef.QualifiedName.Name != ""))) { nameSpace = elementRef.QualifiedName.Namespace; str5 = this.GlobalElementToClrMap(elementRef.QualifiedName); dotnetClassName = this.AddQualifiedNamespaceReference(element.Name, nameSpace, parentNamespace, GlobalXsdType.Element); } else if (((this.schema.Elements[elementRef.QualifiedName] != null) && (elementType.QualifiedName.Name != null)) && (elementType.QualifiedName.Name != "")) { nameSpace = elementRef.QualifiedName.Namespace; str5 = this.GlobalElementToClrMap(elementRef.QualifiedName); dotnetClassName = this.AddQualifiedNamespaceReference(element.Name, nameSpace, parentNamespace, GlobalXsdType.Element); } else { if ((elementRef.QualifiedName.Name == null) || !(elementRef.QualifiedName.Name != "")) { throw new ArgumentException("An element points to a global type or global element that isn't properly qualified"); } nameSpace = parentNamespace; str5 = (string) this.globalQualifiedComplexTypeClasses[elementType.QualifiedName]; dotnetClassName = elementType.Name; if ((elementType.QualifiedName.Namespace != nameSpace) && (elementType.QualifiedName.Namespace != null)) { dotnetClassName = this.AddQualifiedNamespaceReference(dotnetClassName, elementType.QualifiedName.Namespace, parentNamespace, GlobalXsdType.ComplexType); } else { dotnetClassName = this.AddQualifiedNamespaceReference(dotnetClassName, nameSpace, parentNamespace, GlobalXsdType.ComplexType); } } string collectionContainedType = ""; if (maxOccurs > 1M) { collectionContainedType = dotnetClassName; dotnetClassName = str5; } this.code.ClassComplexTypeFieldCode(this.outStream, element.Name, dotnetClassName, collectionContainedType, className, maxOccurs, 1M, this.elementFormDefault, nameSpace, element.IsNillable, elementType.IsAbstract); } ClassConstructor constructor = new ClassConstructor(); if ((elementRef.MinOccurs > 0M) && (element.MinOccurs > 0M)) { constructor.required = true; } else { constructor.required = false; } if (maxOccurs > 1M) { constructor.defaultValue = element.Name; constructor.fieldName = dotnetClassName; if (elementType.IsAbstract) { constructor.datatype = CtorDatatypeContext.PropertyCollectionAbstractComplexType; } else { constructor.datatype = CtorDatatypeContext.PropertyCollectionComplexType; } } else { constructor.defaultValue = element.Name; constructor.fieldName = dotnetClassName; constructor.datatype = CtorDatatypeContext.Property; } ctorList.Add(constructor); } } else { string key = this.CalculateUniqueTypeOrFieldName(element.Name, "", dotnetFieldList); dotnetFieldList.Add(key, element.QualifiedName); if (element.ElementType is XmlSchemaSimpleType) { this.ParseElementSimpleType(element, elementRef, maxOccurs, key, ctorList, parentNamespace); } else { string name = element.SchemaTypeName.Name; string dotNetDatatype = LanguageBase.ReplaceInvalidChars(this.code.FrameworkTypeMapping(name)); this.code.ClassElementFieldCode(this.outStream, dotNetDatatype, name, element.Name, key, maxOccurs, 1M, this.elementFormDefault, false, nameSpace, element.IsNillable); this.BuildConstructorList(element.DefaultValue, element.FixedValue, (elementRef.MinOccurs > 0M) && (element.MinOccurs > 0M), maxOccurs, key, dotNetDatatype, element.Name, ctorList, false); } } } else if (groupBase.Items[i] is XmlSchemaAny) { XmlSchemaAny any = (XmlSchemaAny) groupBase.Items[i]; string str10 = this.CalculateUniqueTypeOrFieldName("Any", "", dotnetFieldList); dotnetFieldList.Add(str10, "Any"); string ns = this.CalculateAnyNamespace(any.Namespace, parentNamespace); this.code.ClassElementFieldCode(this.outStream, "System.Xml.XmlElement", "", "Any", str10, any.MaxOccurs, 1M, this.elementFormDefault, false, ns, false); } else if (groupBase.Items[i] is XmlSchemaGroupRef) { XmlSchemaGroup group = (XmlSchemaGroup) this.schema.Groups[((XmlSchemaGroupRef) groupBase.Items[i]).RefName]; this.ParseGroupBasePass2(group.Particle, className, ctorList, childClasses, parentClassStack, dotnetFieldList, parentNamespace, classReferencesAdded); } else if (groupBase.Items[i] is XmlSchemaGroupBase) { this.ParseGroupBasePass2((XmlSchemaGroupBase) groupBase.Items[i], className, ctorList, childClasses, parentClassStack, dotnetFieldList, parentNamespace, classReferencesAdded); } } }