コード例 #1
0
        /*
		 * Builds a constructor list for elements and attributes with default or required values
		 */
        private void BuildConstructorList(string defaultValue, string fixedValue, bool required, decimal maxOccurs,
            string fieldName, string clrTypeName, string elmtAtrrName, ArrayList ctorList, bool isEnum)
        {
            ClassConstructor ctor = new ClassConstructor();

            if (defaultValue != null || fixedValue != null)
            {
                // field with a default value specified in the schema

                ctor.required = true;

                if (maxOccurs > 1)
                {
                    ctor.defaultValue = elmtAtrrName;
                    ctor.fieldName = fieldName;
                    if (clrTypeName == "System.String")
                        ctor.datatype = CtorDatatypeContext.PropertyCollectionString;
                    else
                        ctor.datatype = CtorDatatypeContext.PropertyCollection;
                }
                else if (isEnum)
                {
                    ctor.defaultValue = defaultValue != null ? defaultValue : fixedValue;
                    ctor.defaultValue = clrTypeName + "." + ctor.defaultValue;
                    ctor.fieldName = fieldName;
                    ctor.datatype = CtorDatatypeContext.ValueTypeDefault;
                }
                else if (code.IsValueType(clrTypeName))
                {
                    ctor.defaultValue = defaultValue != null ? defaultValue : fixedValue;
                    ctor.fieldName = fieldName;
                    ctor.datatype = CtorDatatypeContext.ValueTypeDefault;
                }
                else if (clrTypeName == "System.String")
                {
                    ctor.defaultValue = defaultValue != null ? defaultValue : fixedValue;
                    ctor.fieldName = fieldName;
                    ctor.datatype = CtorDatatypeContext.String;
                }

                ctorList.Add(ctor);
            }
            else
            {
                // required field with no default value specified in the schema
                ctor.required = required;

                if (maxOccurs > 1)
                {
                    ctor.defaultValue = elmtAtrrName;
                    ctor.fieldName = fieldName;
                    if (clrTypeName == "System.String")
                        ctor.datatype = CtorDatatypeContext.PropertyCollectionString;
                    else
                        ctor.datatype = CtorDatatypeContext.PropertyCollection;
                }
                else
                {
                    ctor.defaultValue = "";
                    ctor.fieldName = fieldName;
                    if (isEnum)
                        ctor.datatype = CtorDatatypeContext.ValueType;
                    else if (clrTypeName == "System.DateTime")
                        ctor.datatype = CtorDatatypeContext.DateTime;
                    else if (code.IsValueType(clrTypeName))  // non datetime value type
                        ctor.datatype = CtorDatatypeContext.ValueType;
                    else if (clrTypeName == "System.String")
                        ctor.datatype = CtorDatatypeContext.String;
                    else
                        ctor.datatype = CtorDatatypeContext.Other;
                }
                ctorList.Add(ctor);
            }
        }
コード例 #2
0
        public override void ClassTrailerCode(StreamWriter outStream, string dotnetClassName, ArrayList ctorList,
                                              bool defaultInitialization, bool depthFirstTraversalHooks, bool makeSchemaCompliant, string complexTypeBaseClass, bool baseClassIsMixed, bool mixed, string mixedXsdType)
        {
            // For mixed content (an element that has children and also text), add a special text field.
            // Base class cannot be mixed, otherwise XmlSerializer error will occur.  Can only have 1 XmlText().
            if (mixed && !baseClassIsMixed)
            {
                outStream.WriteLine();

                string clrType;
                if (mixedXsdType.StartsWith("System."))
                {
                    clrType      = mixedXsdType;
                    mixedXsdType = XsdTypeMapping(mixedXsdType);
                }
                else
                {
                    clrType = FrameworkTypeMapping(mixedXsdType);
                }

                if (clrType == "System.DateTime")
                {
                    outStream.WriteLine(MixedDateTimeTemplate, clrType, mixedXsdType, hiddenMemberPrefix, mixedElementFieldName);
                }
                else if (IsValueType(clrType))
                {
                    outStream.WriteLine(MixedValueTypeTemplate, ConvertSystemDatatype(clrType), clrType, hiddenMemberPrefix, mixedElementFieldName);
                }
                else
                {
                    outStream.WriteLine(MixedObjectTemplate, "string", "string", hiddenMemberPrefix, mixedElementFieldName);
                }
            }

            bool inherits = (complexTypeBaseClass != null && complexTypeBaseClass != "");

            // Add a class constructor
            outStream.WriteLine();
            //outStream.WriteLine("\t\t//*********************** Constructor ***********************");
            outStream.WriteLine("\t\tpublic {0}(){1}", CheckForKeywords(dotnetClassName), inherits ? " : base()" : "");
            outStream.WriteLine("\t\t{");

            // Default any DateTime fields to a value.
            for (int i = 0; i < ctorList.Count; i++)
            {
                ClassConstructor ctor = (ClassConstructor)ctorList[i];
                // make sure the datetime fields are initialized to Now if a constructor default value is not set
                if (ctor.datatype == CtorDatatypeContext.DateTime && (!defaultInitialization || (defaultInitialization && !ctor.required)))
                {
                    outStream.WriteLine("\t\t\t{1}{0} = System.DateTime.Now;", ReplaceInvalidChars(ctor.fieldName), hiddenMemberPrefix);
                }
            }

            // If some fields in the class have defaults or fixed values, add a constructor.
            // Also force creation of required attributes and elmenets, so the schema is always valid.
            if (defaultInitialization)
            {
                for (int i = 0; i < ctorList.Count; i++)
                {
                    ClassConstructor ctor = (ClassConstructor)ctorList[i];
                    if (!ctor.required)
                    {
                        continue;
                    }

                    if (ctor.datatype == CtorDatatypeContext.PropertyCollection ||
                        ctor.datatype == CtorDatatypeContext.PropertyCollectionString ||
                        ctor.datatype == CtorDatatypeContext.PropertyCollectionComplexType ||
                        ctor.datatype == CtorDatatypeContext.PropertyCollectionAbstractComplexType)
                    {
                    }
                    else if (ctor.datatype == CtorDatatypeContext.Property)                       // class instance field -- so build code to force the constructor to fire and create an instance
                    {
                        //	outStream.WriteLine("\t\t\t{0} obj{1} = {2};", CheckForKeywords(ctor.fieldName), i, CheckForKeywords(ctor.defaultValue));
                    }
                    else if (ctor.datatype == CtorDatatypeContext.DateTime)                     // standard value type with no default value
                    {
                        outStream.WriteLine("\t\t\t{0} = System.DateTime.Now;", ReplaceInvalidChars(ctor.fieldName));
                    }
                    else if (ctor.datatype == CtorDatatypeContext.ValueType)                     // standard value type with no default value
                    {
                        outStream.WriteLine("\t\t\t{1}{0}Specified = true;", ReplaceInvalidChars(ctor.fieldName), hiddenMemberPrefix);
                    }
                    else if (ctor.datatype == CtorDatatypeContext.ValueTypeDefault)                     //  valuetypes field with a default value
                    {
                        outStream.WriteLine("\t\t\t{0} = {1};", CheckForKeywords(ctor.fieldName), ctor.defaultValue);
                    }
                    else if (ctor.datatype == CtorDatatypeContext.String)
                    {
                        if (ctor.defaultValue == "")
                        {
                            outStream.WriteLine("\t\t\t{0} = string.Empty;", CheckForKeywords(ctor.fieldName), ctor.defaultValue);
                        }
                        else
                        {
                            outStream.WriteLine("\t\t\t{0} = \"{1}\";", CheckForKeywords(ctor.fieldName), ctor.defaultValue);
                        }
                    }
                }
            }

            outStream.WriteLine("\t\t}");

            // Add MakeSchemaCompliant code for required child classes
            if (makeSchemaCompliant)
            {
                outStream.WriteLine();
                //outStream.WriteLine("\t\t//*********************** MakeSchemaCompliant ***********************");
                outStream.WriteLine("\t\t{0}public void MakeSchemaCompliant()", (inherits) ? HideInheritedMethodKeyword : "");
                outStream.WriteLine("\t\t{");
                if (inherits)
                {
                    outStream.WriteLine("\t\t\tbase.MakeSchemaCompliant();");
                }

                for (int i = 0; i < ctorList.Count; i++)
                {
                    ClassConstructor ctor = (ClassConstructor)ctorList[i];
                    if (!ctor.required)
                    {
                        continue;
                    }

                    // removed makeschemacompliant Add calls due to generic list
                    if (ctor.datatype == CtorDatatypeContext.PropertyCollection)
                    {
                        //outStream.WriteLine("\t\t\tif ({0}{1}.Count == 0) {0}{1}.Add();", ReplaceInvalidChars(ctor.defaultValue),
                        //    collectionSuffix);
                    }
                    else if (ctor.datatype == CtorDatatypeContext.PropertyCollectionString)
                    {
                        //outStream.WriteLine("\t\t\tif ({0}{1}.Count == 0) {0}{1}.Add(\"\");", ReplaceInvalidChars(ctor.defaultValue),
                        //    collectionSuffix);
                    }
                    else if (ctor.datatype == CtorDatatypeContext.PropertyCollectionComplexType)
                    {
                        outStream.WriteLine("\t\t\tforeach ({0} _c in {1}) _c.MakeSchemaCompliant();", CheckForKeywords(ctor.fieldName),
                                            ReplaceInvalidChars(ctor.defaultValue));
                    }
                    else if (ctor.datatype == CtorDatatypeContext.PropertyCollectionAbstractComplexType)
                    {
                        // note: there is no .Add() method to call for the "abstract" case -- since the code generator has
                        //  no idea what type will be added into the collection.
                        outStream.WriteLine("\t\t\tforeach ({0} _c in {1}) _c.MakeSchemaCompliant();", CheckForKeywords(ctor.fieldName),
                                            ReplaceInvalidChars(ctor.defaultValue));
                    }
                    else if (ctor.datatype == CtorDatatypeContext.Property)                       // class instance field -- so build code to force the constructor to fire and create an instance
                    {
                        outStream.WriteLine("\t\t\t{0}.MakeSchemaCompliant();", CheckForKeywords(ctor.defaultValue));
                    }
                }

                outStream.WriteLine("\t\t}");
            }

            // Add DepthFirstTraversal hooks
            if (depthFirstTraversalHooks)
            {
                outStream.WriteLine();
                //outStream.WriteLine("\t\t//*********************** DepthFirstTraversal Event ***********************");
                outStream.WriteLine("\t\t{0}public static event DepthFirstTraversalDelegate DepthFirstTraversalEvent;", (inherits) ? HideInheritedMethodKeyword : "");
                outStream.WriteLine("\t\t{0}public void DepthFirstTraversal(object parent, object context)", (inherits) ? HideInheritedMethodKeyword : "");
                outStream.WriteLine("\t\t{");
                outStream.WriteLine("\t\t\tif (DepthFirstTraversalEvent != null) DepthFirstTraversalEvent(this, parent, context);");
                if (inherits)
                {
                    outStream.WriteLine("\t\t\tbase.DepthFirstTraversal(parent, context);");
                }

                for (int i = 0; i < ctorList.Count; i++)
                {
                    ClassConstructor ctor = (ClassConstructor)ctorList[i];
                    if (ctor.datatype == CtorDatatypeContext.PropertyCollectionComplexType || ctor.datatype == CtorDatatypeContext.PropertyCollectionAbstractComplexType)
                    {
                        outStream.WriteLine("\t\t\tif ({0}{1} != null) foreach ({3} _d in {4}{5}) _d.DepthFirstTraversal(this, context);", hiddenMemberPrefix, ReplaceInvalidChars(ctor.defaultValue), collectionSuffix,
                                            CheckForKeywords(ctor.fieldName), hiddenMemberPrefix, ReplaceInvalidChars(ctor.defaultValue));
                    }
                    else if (ctor.datatype == CtorDatatypeContext.Property)                       // class instance field -- so build code to force the constructor to fire and create an instance
                    {
                        outStream.WriteLine("\t\t\tif ({0}{1} != null) {0}{1}.DepthFirstTraversal(this, context);", hiddenMemberPrefix, ReplaceInvalidChars(ctor.defaultValue));
                    }
                }

                outStream.WriteLine("\t\t}");
            }

            outStream.WriteLine("\t}");
        }
コード例 #3
0
        /*
         * Add class fields for xsd:all, xsd:choice and xsd:sequence xml elements.
         * These will either be native CLR typed fields or other schema classes.
         */
        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();  // avoid duplicate complexType field references within a .net class

            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)schema.Elements[elementRef.QualifiedName];
                    if (element == null) element = elementRef;
                    maxOccurs = elementRef.MaxOccurs > maxOccurs ? elementRef.MaxOccurs : maxOccurs;

                    // for unqualified elements or attributes, element/attribute.QualifiedName.Namespace will be empty -- so use parentNamespace
                    string ns = element.QualifiedName.Namespace != "" ? element.QualifiedName.Namespace : parentNamespace;

                    if (element.ElementType is XmlSchemaComplexType && element.SchemaTypeName.Namespace != Globals.XSD_NAMESPACE)
                    {
                        // this will generate to a class in code

                        string dotnetTypeName = "";
                        XmlSchemaComplexType elementComplex = (XmlSchemaComplexType)element.ElementType;

                        // avoid duplicate references for the same type (allowed in xsd -- not in .net)
                        string fname = element.Name;
                        if (classReferencesAdded.ContainsKey(fname))
                        {
                            continue;
                            //fname = element.Name + "2";
                            //while (classReferencesAdded.ContainsKey(fname))
                            //    fname = fname + "2";
                        }
                        else
                            classReferencesAdded.Add(element.Name, element.Name);

                        // The complex type is locally defined so a child class needs to be created.  
                        if ((element == elementRef) && (schema.SchemaTypes[elementComplex.QualifiedName] == null))
                        {
                            // The complex type is locally defined.  Locally scoped complexTypes may not be unique 
                            string parentList = "";
                            foreach (string s in parentClassStack)
                            {
                                parentList += s;
                            }
                            dotnetTypeName = (string)globalQualifiedComplexTypeClasses[element.QualifiedName + parentList];
                            childClasses.Add(new ChildComplexType(elementComplex, element.Name, dotnetTypeName, ns, element.QualifiedName));

                            dotnetTypeName = LanguageBase.ReplaceInvalidChars(dotnetTypeName);
                            code.ClassComplexTypeFieldCode(outStream, element.Name, fname, dotnetTypeName, dotnetTypeName, className,
                                maxOccurs, 1, elementFormDefault, ns, element.IsNillable, false);
                        }
                        else  // not a locally defined complexType 
                        {
                            // The complexType is either globally defined at the <xsd:schema> level,
                            // or it's tied to a globally defined element.  In the case of the 
                            // globally defined complexType at the <xsd:schema> level, elementComplex.Name 
                            // will not be null because the complexType will have name.  In that case 
                            // we use the complexType name for the class name.

                            string qualifiedTypeName = "";

                            if ((elementComplex.QualifiedName.Name == null || elementComplex.QualifiedName.Name == "") &&
                                (elementRef.QualifiedName.Name != null && elementRef.QualifiedName.Name != ""))
                            {
                                // global element
                                ns = elementRef.QualifiedName.Namespace;  // element's referenced namespace is used
                                //qualifiedTypeName = (string) globalQualifiedComplexTypeClasses[elementRef.QualifiedName];
                                qualifiedTypeName = GlobalElementToClrMap(elementRef.QualifiedName);
                                dotnetTypeName = AddQualifiedNamespaceReference(element.Name, ns, parentNamespace, GlobalXsdType.Element);
                            }
                            else if ((schema.Elements[elementRef.QualifiedName] != null) && (elementComplex.QualifiedName.Name != null && elementComplex.QualifiedName.Name != ""))
                            {
                                // An element who's "ref" attribute points to a global typed element (name and type are set and has no schema children)
                                //  use the ref in this case -- and not the type
                                ns = elementRef.QualifiedName.Namespace;  // element's referenced namespace is used
                                //qualifiedTypeName = (string) globalQualifiedComplexTypeClasses[elementRef.QualifiedName];
                                qualifiedTypeName = GlobalElementToClrMap(elementRef.QualifiedName);
                                dotnetTypeName = AddQualifiedNamespaceReference(element.Name, ns, parentNamespace, GlobalXsdType.Element);
                            }
                            else if (elementRef.QualifiedName.Name != null && elementRef.QualifiedName.Name != "")
                            {
                                // named complexType
                                ns = parentNamespace;  //elements of a "type" take their parent namespace.  The children go into the "types" namespace.
                                qualifiedTypeName = (string)globalQualifiedComplexTypeClasses[elementComplex.QualifiedName];
                                dotnetTypeName = elementComplex.Name;

                                if (elementComplex.QualifiedName.Namespace != ns && elementComplex.QualifiedName.Namespace != null)
                                    dotnetTypeName = AddQualifiedNamespaceReference(dotnetTypeName, elementComplex.QualifiedName.Namespace, parentNamespace, GlobalXsdType.ComplexType);
                                else
                                    dotnetTypeName = AddQualifiedNamespaceReference(dotnetTypeName, ns, parentNamespace, GlobalXsdType.ComplexType);
                            }
                            else
                            {
                                // shouldn't happen
                                throw new ArgumentException("An element points to a global type or global element that isn't properly qualified");
                            }

                            string collectionContainedType = "";
                            if (maxOccurs > 1)
                            {
                                // collections are always local to the namespace
                                collectionContainedType = dotnetTypeName; // fully namespace referenced with namesapce
                                dotnetTypeName = qualifiedTypeName;  // reference removed for collection class
                            }

                            dotnetTypeName = LanguageBase.ReplaceInvalidChars(dotnetTypeName);
                            code.ClassComplexTypeFieldCode(outStream, element.Name, fname, dotnetTypeName, collectionContainedType, className,
                                maxOccurs, 1, elementFormDefault, ns, element.IsNillable, elementComplex.IsAbstract);
                        }

                        // If the subelement is required, then force it's creation through constructor and 
                        //  a special MakeSchemaCompliant method.

                        ClassConstructor ctor = new ClassConstructor();
                        if (elementRef.MinOccurs > 0 && element.MinOccurs > 0)
                            ctor.required = true;   // required child complex types
                        else
                            ctor.required = false;  // non required child complex tyes

                        if (maxOccurs > 1)
                        {
                            ctor.defaultValue = element.Name;
                            ctor.fieldName = dotnetTypeName;

                            if (elementComplex.IsAbstract)
                                ctor.datatype = CtorDatatypeContext.PropertyCollectionAbstractComplexType;
                            else
                                ctor.datatype = CtorDatatypeContext.PropertyCollectionComplexType;
                        }
                        else
                        {
                            ctor.defaultValue = element.Name;
                            ctor.fieldName = dotnetTypeName;
                            ctor.datatype = CtorDatatypeContext.Property;
                        }
                        ctorList.Add(ctor);
                    }
                    else  // not a ComplexType -- so this will be a leaf-node class field in code
                    {
                        string dotnetElementName = CalculateUniqueTypeOrFieldName(element.Name, "", dotnetFieldList);
                        dotnetFieldList.Add(dotnetElementName, element.QualifiedName);

                        if (element.ElementType is XmlSchemaSimpleType)
                        {
                            ParseElementSimpleType(element, elementRef, maxOccurs, dotnetElementName, ctorList, parentNamespace);
                        }
                        else
                        {
                            string xsdTypeName = element.SchemaTypeName.Name;
                            string clrTypeName = code.FrameworkTypeMapping(xsdTypeName);

                            clrTypeName = LanguageBase.ReplaceInvalidChars(clrTypeName);
                            code.ClassElementFieldCode(outStream, clrTypeName, xsdTypeName,
                                element.Name, dotnetElementName, maxOccurs, 1, elementFormDefault, false, ns,
                                element.IsNillable);

                            BuildConstructorList(element.DefaultValue, element.FixedValue, (elementRef.MinOccurs > 0 && element.MinOccurs > 0),
                                maxOccurs, dotnetElementName, clrTypeName, element.Name, ctorList, false);
                        }
                    }
                }
                else if (groupBase.Items[i] is XmlSchemaAny)
                {
                    XmlSchemaAny any = (XmlSchemaAny)groupBase.Items[i];

                    string dotnetElementName = CalculateUniqueTypeOrFieldName("Any", "", dotnetFieldList);
                    dotnetFieldList.Add(dotnetElementName, "Any");

                    string ns = CalculateAnyNamespace(any.Namespace, parentNamespace);
                    code.ClassElementFieldCode(outStream, "System.Xml.XmlElement", "", "Any", dotnetElementName, any.MaxOccurs, 1, elementFormDefault,
                        false, ns, false);
                }
                else if (groupBase.Items[i] is XmlSchemaGroupRef)
                {
                    XmlSchemaGroup group = (XmlSchemaGroup)schema.Groups[((XmlSchemaGroupRef)groupBase.Items[i]).RefName];
                    ParseGroupBasePass2(group.Particle, className, ctorList, childClasses, parentClassStack, dotnetFieldList, parentNamespace, classReferencesAdded);
                }
                else if (groupBase.Items[i] is XmlSchemaGroupBase)
                {
                    // Particle inside a particle : ie. <xsd:sequence> <xsd:choice/> </xsd:sequence>
                    ParseGroupBasePass2((XmlSchemaGroupBase)groupBase.Items[i], className, ctorList, childClasses, parentClassStack, dotnetFieldList, parentNamespace, classReferencesAdded);
                }
            }
        }
コード例 #4
0
        public override void ClassTrailerCode(StreamWriter outStream, string dotnetClassName, ArrayList ctorList,
                                              bool defaultInitialization, bool depthFirstTraversalHooks, bool makeSchemaCompliant, string complexTypeBaseClass, bool baseClassIsMixed, bool mixed, string mixedXsdType)
        {
            // For mixed content (an element that has children and also text), add a special text field.
            // Base class cannot be mixed, otherwise XmlSerializer error will occur.  Can only have 1 XmlText().
            if (mixed && !baseClassIsMixed)
            {
                outStream.WriteLine();

                string clrType;
                if (mixedXsdType.StartsWith("System."))
                {
                    clrType      = mixedXsdType;
                    mixedXsdType = XsdTypeMapping(mixedXsdType);
                }
                else
                {
                    clrType = FrameworkTypeMapping(mixedXsdType);
                }

                if (clrType == "System.DateTime")
                {
                    outStream.WriteLine(MixedDateTimeTemplate, ConvertSystemDatatype(clrType), mixedXsdType, hiddenMemberPrefix, mixedElementFieldName);
                }
                else if (IsValueType(clrType))
                {
                    outStream.WriteLine(MixedValueTypeTemplate, ConvertSystemDatatype(clrType), clrType, hiddenMemberPrefix, mixedElementFieldName);
                }
                else
                {
                    outStream.WriteLine(MixedObjectTemplate, "String", "String", hiddenMemberPrefix, mixedElementFieldName);
                }
            }

            bool inherits = (complexTypeBaseClass != null && complexTypeBaseClass != "");

            // Add class constructor
            outStream.WriteLine();
            outStream.WriteLine("\t\t'*********************** Constructor ***********************");
            outStream.WriteLine("\t\tPublic Sub New()");
            if (inherits)
            {
                outStream.WriteLine("\t\t\tMyBase.New()");
            }

            // Default any DateTime fields to a value.
            for (int i = 0; i < ctorList.Count; i++)
            {
                ClassConstructor ctor = (ClassConstructor)ctorList[i];
                // make sure the datetime fields are initialized to Now if a constructor default value is not set
                if (ctor.datatype == CtorDatatypeContext.DateTime && (!defaultInitialization || (defaultInitialization && !ctor.required)))
                {
                    outStream.WriteLine("\t\t\t{1}{0} = DateTime.Now", ReplaceInvalidChars(ctor.fieldName), hiddenMemberPrefix);
                }
            }

            // If some fields in the class have defaults or fixed values, add a constructor.
            // Also force creation of required attributes and elmenets, so the schema is always valid.
            if (defaultInitialization)
            {
                for (int i = 0; i < ctorList.Count; i++)
                {
                    ClassConstructor ctor = (ClassConstructor)ctorList[i];
                    if (!ctor.required)
                    {
                        continue;
                    }

                    if (ctor.datatype == CtorDatatypeContext.PropertyCollection ||
                        ctor.datatype == CtorDatatypeContext.PropertyCollectionString ||
                        ctor.datatype == CtorDatatypeContext.PropertyCollectionComplexType ||
                        ctor.datatype == CtorDatatypeContext.PropertyCollectionAbstractComplexType)
                    {
                    }
                    else if (ctor.datatype == CtorDatatypeContext.Property)                      // class instance field -- so build code to force the constructor to fire and create an instance
                    {
                        //outStream.WriteLine("\t\t\tDim obj{1} As {0} = {2}", CheckForKeywords(ctor.fieldName), i,
                        //	CheckForKeywords(ctor.defaultValue));
                    }
                    else if (ctor.datatype == CtorDatatypeContext.DateTime)                     // standard value type with no default value
                    {
                        outStream.WriteLine("\t\t\t{0} = DateTime.Now", ReplaceInvalidChars(ctor.fieldName));
                    }
                    else if (ctor.datatype == CtorDatatypeContext.ValueType)                       // standard value type with default value
                    {
                        outStream.WriteLine("\t\t\t{1}{0}Specified = True", ReplaceInvalidChars(ctor.fieldName), hiddenMemberPrefix);
                    }
                    else if (ctor.datatype == CtorDatatypeContext.ValueTypeDefault)                      // valuetypes field with a default value
                    {
                        outStream.WriteLine("\t\t\t{0} = {1}", CheckForKeywords(ctor.fieldName), ctor.defaultValue);
                    }
                    else if (ctor.datatype == CtorDatatypeContext.String)
                    {
                        if (ctor.defaultValue == "")
                        {
                            outStream.WriteLine("\t\t\t{0} = String.Empty", CheckForKeywords(ctor.fieldName), ctor.defaultValue);
                        }
                        else
                        {
                            outStream.WriteLine("\t\t\t{0} = \"{1}\"", CheckForKeywords(ctor.fieldName), ctor.defaultValue);
                        }
                    }
                }
            }

            outStream.WriteLine("\t\tEnd Sub");

            // Add MakeSchemaCompliant code for required child classes
            if (makeSchemaCompliant)
            {
                outStream.WriteLine();
                outStream.WriteLine("\t\t'*********************** MakeSchemaCompliant ***********************");
                outStream.WriteLine("\t\tPublic {0}Sub MakeSchemaCompliant()", (inherits) ? HideInheritedMethodKeyword : "");
                if (inherits)
                {
                    outStream.WriteLine("\t\t\tMyBase.MakeSchemaCompliant()");
                }

                for (int i = 0; i < ctorList.Count; i++)
                {
                    ClassConstructor ctor = (ClassConstructor)ctorList[i];
                    if (!ctor.required)
                    {
                        continue;
                    }

                    // removed makeschemacompliant Add calls due to generic list
                    if (ctor.datatype == CtorDatatypeContext.PropertyCollection)
                    {
                        //outStream.WriteLine("\t\t\tIf {0}{1}.Count = 0 Then {0}{1}.Add()", ReplaceInvalidChars(ctor.defaultValue), collectionSuffix);
                    }
                    else if (ctor.datatype == CtorDatatypeContext.PropertyCollectionString)
                    {
                        //outStream.WriteLine("\t\t\tIf {0}{1}.Count = 0 Then {0}{1}.Add(\"\")", ReplaceInvalidChars(ctor.defaultValue), collectionSuffix);
                    }
                    else if (ctor.datatype == CtorDatatypeContext.PropertyCollectionComplexType)
                    {
                        outStream.WriteLine("\t\t\tFor Each _c as {0} in {1}", CheckForKeywords(ctor.fieldName),
                                            ReplaceInvalidChars(ctor.defaultValue));
                        outStream.WriteLine("\t\t\t\t_c.MakeSchemaCompliant()");
                        outStream.WriteLine("\t\t\tNext");
                    }
                    else if (ctor.datatype == CtorDatatypeContext.PropertyCollectionAbstractComplexType)
                    {
                        outStream.WriteLine("\t\t\tFor Each _c as {0} in {1}", CheckForKeywords(ctor.fieldName),
                                            ReplaceInvalidChars(ctor.defaultValue));
                        outStream.WriteLine("\t\t\t\t_c.MakeSchemaCompliant()");
                        outStream.WriteLine("\t\t\tNext");
                    }
                    else if (ctor.datatype == CtorDatatypeContext.Property)                       // class instance field -- so build code to force the constructor to fire and create an instance
                    {
                        outStream.WriteLine("\t\t\t{0}.MakeSchemaCompliant()", CheckForKeywords(ctor.defaultValue));
                    }
                }

                outStream.WriteLine("\t\tEnd Sub");
            }

            // Add DepthFirstTraversal hooks
            if (depthFirstTraversalHooks)
            {
                outStream.WriteLine();
                outStream.WriteLine("\t\t'*********************** DepthFirstTraversal Event ***********************");
                outStream.WriteLine("\t\tPublic Shared {0}Event DepthFirstTraversalEvent As DepthFirstTraversalDelegate", (inherits) ? HideInheritedMethodKeyword : "");
                outStream.WriteLine("\t\tPublic {0}Sub DepthFirstTraversal(parent As Object, context As Object)", (inherits) ? HideInheritedMethodKeyword : "");
                outStream.WriteLine("\t\t\tRaiseEvent DepthFirstTraversalEvent(Me, parent, context)");
                if (inherits)
                {
                    outStream.WriteLine("\t\t\tMyBase.DepthFirstTraversal(parent, context)");
                }

                for (int i = 0; i < ctorList.Count; i++)
                {
                    ClassConstructor ctor = (ClassConstructor)ctorList[i];
                    if (ctor.datatype == CtorDatatypeContext.PropertyCollectionComplexType || ctor.datatype == CtorDatatypeContext.PropertyCollectionAbstractComplexType)
                    {
                        outStream.WriteLine("\t\t\tIf Not({0}{1} Is Nothing) Then", hiddenMemberPrefix, ReplaceInvalidChars(ctor.defaultValue));
                        outStream.WriteLine("\t\t\t\tFor Each _d As {2} in {0}{1}", hiddenMemberPrefix, ReplaceInvalidChars(ctor.defaultValue), CheckForKeywords(ctor.fieldName));
                        outStream.WriteLine("\t\t\t\t\t_d.DepthFirstTraversal(Me, context)");
                        outStream.WriteLine("\t\t\t\tNext");
                        outStream.WriteLine("\t\t\tEnd If");
                    }
                    else if (ctor.datatype == CtorDatatypeContext.Property)                       // class instance field -- so build code to force the constructor to fire and create an instance
                    {
                        outStream.WriteLine("\t\t\tIf Not({0}{1} is Nothing) Then {0}{1}.DepthFirstTraversal(Me, context)", hiddenMemberPrefix, ReplaceInvalidChars(ctor.defaultValue));
                    }
                }

                outStream.WriteLine("\t\tEnd Sub");
            }

            outStream.WriteLine("\tEnd Class");
        }