/// <summary> /// Acord specific helper routines /// </summary> public virtual void AcordTransactCodes(GeneratorStream generator, String elementName, string enumName, string tcCode, string valueCode, bool privateCodes) { /*outStream.WriteLine(); * * if (privateCodes) * outStream.WriteLine(AcordPrivateTCTemplate, elementName, enumName, tcCode, valueCode); * else * outStream.WriteLine(AcordTCTemplate, elementName, enumName, tcCode, valueCode);*/ }
/// <summary> /// Add a field to the class that will persist itself to an element -- who can have children (ComplexType) /// </summary> /// <param name="outStream"></param> /// <param name="elementName">Name attribute on a xsd:element.</element></param> /// <param name="dupElementName">Rename of the attribute on the xsd:element in case of duplicates in the xsd</element></param> /// <param name="dotnetTypeName">.NET class being referenced</param> /// <param name="parentContainerClassName">Owner class</param> /// <param name="fieldOccurs">maxOccurs on the field from XSD</param> /// <param name="particleOccurs">maxOccurs on the particle from XSD if the field is an instance</param> /// <param name="elementFormDefault">whether the XML attribute name generated by the XmlSerializer is qualified</param> /// <param name="isElementNullable">Set the IsNullable element paramter = true, causing xsi:nil="true" for null elements</param> /// <param name="isAbstract">complex type is marked as abstract, so it cannot be created</param> public virtual void ClassComplexTypeFieldCode(GeneratorStream generator, String elementName, string dupElementName, String dotnetTypeName, String collectionContainedType, String parentContainerClassName, decimal fieldOccurs, decimal particleOccurs, XmlSchemaForm elementFormDefault, string ns, bool isElementNullable, bool isAbstract, String default_value, bool is_required) { string fieldName1 = ReplaceInvalidChars(dupElementName); string fieldName2 = CheckForKeywords(fieldName1); string fieldType1 = CheckForKeywords(dotnetTypeName); string fieldType2 = ReplaceInvalidChars(dotnetTypeName); collectionContainedType = CheckForKeywords(collectionContainedType); string nameSpace = ""; string schemaForm = ""; if (elementFormDefault == XmlSchemaForm.Qualified || elementFormDefault == XmlSchemaForm.Unqualified) { schemaForm = ",Form" + AttributeAssignmentOperator + "XmlSchemaForm." + elementFormDefault.ToString(); nameSpace = CalculateNamespace(schemaTargetNamespace, ns, false); } if (particleOccurs > 1 || fieldOccurs > 1) { generator.put_FieldCollectionTemplate(collectionContainedType, fieldName1, dupElementName, default_value, is_required); //outStream.WriteLine(FieldCollectionTemplate, fieldType2, fieldType1, elementName, schemaForm, fieldName1, "", nameSpace, // hiddenMemberPrefix, collectionSuffix, isElementNullable.ToString().ToLower(), collectionContainedType); } else if (isAbstract) { //outStream.WriteLine(FieldAbstractClassTemplate, fieldName1, fieldType1, elementName, schemaForm, fieldName2, nameSpace, hiddenMemberPrefix, // isElementNullable.ToString().ToLower()); } else { generator.put_FieldClassTemplate(fieldType1, fieldName1, dupElementName, default_value, is_required); //outStream.WriteLine(FieldClassTemplate, fieldName1, fieldType1, elementName, schemaForm, fieldName2, nameSpace, hiddenMemberPrefix, // isElementNullable.ToString().ToLower()); } }
public override void NamespaceHeaderCode(GeneratorStream generator, String ns, String schemaFile, Hashtable forwardDeclarations, string targetNamespace, Hashtable enumerations, bool depthFirstTraversalHooks, ArrayList importedReferences) { schemaTargetNamespace = targetNamespace; /*outStream.WriteLine("#pragma once"); * outStream.WriteLine(); * outStream.WriteLine("// Copyright 2008, Microsoft Corporation and 2019 Alex Mytnyk"); * outStream.WriteLine("// Sample Code - Use restricted to terms of use defined in the accompanying license agreement (EULA.doc)"); * outStream.WriteLine(); * outStream.WriteLine("//--------------------------------------------------------------"); * outStream.WriteLine("// Autogenerated by XSDObjectGen version {0}", * this.GetType().Assembly.GetName(false).Version); * outStream.WriteLine("// Schema file: {0}", schemaFile); * outStream.WriteLine("// Creation Date: {0}", DateTime.Now.ToString()); * outStream.WriteLine("//--------------------------------------------------------------"); * outStream.WriteLine();*/ //outStream.WriteLine("using System;"); //outStream.WriteLine("using System.Xml.Serialization;"); //outStream.WriteLine("using System.Collections;"); //outStream.WriteLine("using System.Collections.Generic;"); //outStream.WriteLine("using System.Xml.Schema;"); //outStream.WriteLine("using System.ComponentModel;"); /*outStream.WriteLine("#include <iostream>"); * outStream.WriteLine("#include <string>"); * outStream.WriteLine("#include <ctime>"); * * outStream.WriteLine(); * outStream.WriteLine("namespace {0}", ns); * outStream.WriteLine("{"); * outStream.WriteLine(); * outStream.WriteLine("\tstruct Declarations"); * outStream.WriteLine("\t{"); * outStream.WriteLine(string.Format("\t\tconst std::string SchemaVersion = \"{0}\";", targetNamespace)); * outStream.WriteLine("\t};"); * outStream.WriteLine("\t//BEGIN_CPP2SERIALIZE");*/ if (depthFirstTraversalHooks) { //outStream.WriteLine("\tpublic delegate void DepthFirstTraversalDelegate(object instance, object parent, object context);"); //outStream.WriteLine(); } // Add enumerations foreach (string key in enumerations.Keys) { //outStream.WriteLine("\t[Serializable]"); string code = ""; code += string.Format("\tenum {0}", key) + "\n"; code += "\t{\n"; ArrayList enumValues = (ArrayList)enumerations[key]; for (int i = 0; i < enumValues.Count; i++) { string[] enumValue = (string[])enumValues[i]; if (i == (enumValues.Count - 1)) { if (key.StartsWith("OLI_LU_")) { code += string.Format("\t\t{1} = {0}", enumValue[0], CheckForKeywords(enumValue[1])) + "\n"; } else { code += string.Format("\t\t{1}", enumValue[0], CheckForKeywords(enumValue[1])) + "\n"; } } else { if (key.StartsWith("OLI_LU_")) { code += string.Format("\t\t{1} = {0},", enumValue[0], CheckForKeywords(enumValue[1])) + "\n"; } else { code += string.Format("\t\t{1},", enumValue[0], CheckForKeywords(enumValue[1])) + "\n"; } } } code += "\t};"; generator.put_Enum(key, enumValues, CheckForKeywords); } }
public override void NamespaceTrailerCode(GeneratorStream generator, string ns) { //outStream.WriteLine("}"); //outStream.WriteLine(); //outStream.WriteLine("#pragma warning restore 1591 "); }
public override void ClassTrailerCode(GeneratorStream generator, 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) { 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("\t\t//*********************** Constructor ***********************"); generator.put_Constructor(CheckForKeywords(dotnetClassName), ""); //outStream.WriteLine("\t\t{0}(){1}", CheckForKeywords(dotnetClassName), inherits ? " : super()" : ""); //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); * } * }*/ //outStream.WriteLine("\t\t}"); // End of constructor // 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); * } * } * }*/ // 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}");*/ } generator.end_class(); //End of class }
public override void ClassHeaderCode(GeneratorStream generator, string dotnetClassName, string elementName, string complexTypeBaseClass, bool baseIsAbstract, bool isSchemaType, bool isAbstract, bool isLocalComplexType, Hashtable enumerableClasses, string ns, XmlSchemaForm elementFormDefault, string annotation, bool isElementNullable, ArrayList xmlIncludedClasses, bool globalElementAndSchemaTypeHaveSameName) { string nameSpace = ""; if (isSchemaType) { if (elementFormDefault == XmlSchemaForm.Qualified || elementFormDefault == XmlSchemaForm.Unqualified) { nameSpace = CalculateNamespace(schemaTargetNamespace, ns, false); } if (globalElementAndSchemaTypeHaveSameName) { //outStream.WriteLine("\t[XmlRoot(ElementName=\"{0}\"{1},IsNullable={2}),Serializable]", // elementName, nameSpace, isElementNullable.ToString().ToLower()); //outStream.WriteLine("\t[XmlType(TypeName=\"{0}\"{1})]", // dotnetClassName, nameSpace); } else { //outStream.WriteLine("\t[XmlType(TypeName=\"{0}\"{1}),Serializable]", dotnetClassName, nameSpace); } } else if (isLocalComplexType) { if (elementFormDefault == XmlSchemaForm.Qualified || elementFormDefault == XmlSchemaForm.Unqualified) { nameSpace = CalculateNamespace(schemaTargetNamespace, ns, false); } //outStream.WriteLine("\t[XmlType(TypeName=\"{0}\"{1}),Serializable]", // dotnetClassName, nameSpace); } else { // possible root node element -- so put namespace on the element if targetNamesapce has been set nameSpace = CalculateNamespace(schemaTargetNamespace, ns, false); //outStream.WriteLine("\t//MAIN_CLASS"); //outStream.WriteLine("\t[XmlRoot(ElementName=\"{0}\"{1},IsNullable={2}),Serializable]", // elementName, nameSpace, isElementNullable.ToString().ToLower()); } // Add necessary XmlInludes for abstract derived types used in the class foreach (string xmlIncludeClass in xmlIncludedClasses) { //outStream.WriteLine("\t[XmlInclude(typeof({0}))]", CheckForKeywords(xmlIncludeClass)); } string className = CheckForKeywords(dotnetClassName); // outStream.WriteLine("\t//CLASS"); //outStream.Write("\t{1}{2}struct {0}", className, isAbstract ? "abstract " : "", partialClasses ? PartialKeyword : ""); // setup inheritance for <xsd:extension base="class"> string inheritance = String.Empty; if (complexTypeBaseClass != null && complexTypeBaseClass != "") { inheritance = CheckForKeywords(complexTypeBaseClass); } generator.begin_class(className, isAbstract ? "abstract " : "", inheritance); //outStream.WriteLine(); //outStream.WriteLine("\t{"); // setup enumerability over a contained collection if (enumerableClasses.ContainsKey(dotnetClassName)) { ArrayList values = (ArrayList)enumerableClasses[dotnetClassName]; string collectionName = (string)values[0]; collectionName = ReplaceInvalidChars(collectionName); //outStream.WriteLine(ClassEnumerabilityTemplate, collectionName, // ConvertSystemDatatype((string)values[1]), collectionSuffix, hiddenMemberPrefix); } }
/// <summary> /// Add the class keyword and inheritance relationship if necessary /// </summary> /// <param name="outStream">Out file</param> /// <param name="dotnetClassName">Classname to be used in code</param> /// <param name="elementName">Xml element for the class</param> /// <param name="complexTypeBaseClass">Base class</param> /// <param name="baseIsAbstract">Base class is an abstract type</param> /// <param name="isSchemaType">Is a global ComplexType defined at the schema level</param> /// <param name="isAbstract">Is the complexType an Abstract type -- marked with abstract="true"</param> /// <param name="isLocalComplexType">Locally scoped complexType (not a child of schema tag)</schema></param> /// <param name="enumerableClasses">List of enumerable classes</param> /// <param name="ns">namespace</param> /// <param name="elementFormDefault">whether the xml element for the class will be namespace qualified</param> /// <param name="annotation">complexType annotation</param> /// <param name="isElementNullable">Set the IsNullable element paramter = true, causing xsi:nil="true" for null elements</param> /// <param name="xmlIncludedClasses">List of classes to put in XmlIncludeAttributes -- needed for abstract ComplexTypes</param> /// <param name="globalElementAndSchemaTypeHaveSameName">For global schema types where an existing global element also has the same name</param> public abstract void ClassHeaderCode(GeneratorStream generator, string dotnetClassName, string elementName, string complexTypeBaseClass, bool baseIsAbstract, bool isSchemaType, bool isAbstract, bool isLocalComplexType, Hashtable enumerableClasses, string ns, XmlSchemaForm elementFormDefault, string annotation, bool isElementNullable, ArrayList xmlIncludedClasses, bool globalElementAndSchemaTypeHaveSameName);
/// <summary> /// Close the namespace containing all of the generated types /// </summary> /// <param name="outStream"></param> /// <param name="ns">.net namespace string</param> public abstract void NamespaceTrailerCode(GeneratorStream generator, string ns);
/// <summary> /// Add the namespace, using statements, enumerations, and any forward declarations /// </summary> /// <param name="outStream"></param> /// <param name="ns">.NET namespace to contain all generated types</param> /// <param name="schemaFile">XSD Schema file used to generate the types</param> /// <param name="forwardDeclarations">Forward declarations needed in MC++</param> /// <param name="targetNamespace">Optional qualified namespace from the XSD schema</param> /// <param name="enumerations">Enumeration list to build enum types</param> /// <param name="depthFirstTraversalHooks">Create DepthFirstTraversal hook events</param> /// <param name="importedReferences">Namespaces imported from other schemas</param> public abstract void NamespaceHeaderCode(GeneratorStream generator, String ns, String schemaFile, Hashtable forwardDeclarations, string targetNamespace, Hashtable enumerations, bool depthFirstTraversalHooks, ArrayList importedReferences);
/// <summary> /// Add a field to the class that will persist itself to an element (element with no children) /// </summary> /// <param name="outStream"></param> /// <param name="dotNetDatatype">.NET System datatype</param> /// <param name="xsdDatatype">XSD equivelent datatype</param> /// <param name="fieldName">Name of the element that will be a new field in code</param> /// <param name="dotnetFieldName">Name of the .net class field -- different from fieldName if duplicates occur</param> /// <param name="fieldOccurs">maxOccurs on the field from XSD</param> /// <param name="particleOccurs">maxOccurs on the particle from XSD if the field is an instance</param> /// <param name="elementFormDefault">whether the XML attribute name generated by the XmlSerializer is qualified</param> /// <param name="isSchemaEnumerationType">some languages like MC++ need to perform special logic if the field's type is an enumeration</param> /// <param name="ns">element namespace</param> /// <param name="isElementNullable">Set the IsNullable element paramter = true, causing xsi:nil="true" for null elements</param> public virtual void ClassElementFieldCode(GeneratorStream generator, string dotNetDatatype, string xsdDatatype, string fieldName, string dotnetFieldName, decimal fieldOccurs, decimal particleOccurs, XmlSchemaForm elementFormDefault, bool isSchemaEnumerationType, string ns, bool isElementNullable, String default_value, bool is_required) { string elementName = fieldName; string fieldName1 = ReplaceInvalidChars(dotnetFieldName); string fieldName2 = CheckForKeywords(dotnetFieldName); string fieldType = ConvertSystemDatatype(dotNetDatatype); string nameSpace = ""; string schemaForm = ""; if (elementFormDefault == XmlSchemaForm.Qualified || elementFormDefault == XmlSchemaForm.Unqualified) { schemaForm = ",Form" + AttributeAssignmentOperator + "XmlSchemaForm." + elementFormDefault.ToString(); nameSpace = CalculateNamespace(schemaTargetNamespace, ns, dotNetDatatype == "System.Xml.XmlElement"); // special case for <xs:any> elements // <xs:any> has XmlElement dotnet type. if (dotNetDatatype == "System.Xml.XmlElement" && nameSpace != "") { nameSpace = "Name" + AttributeAssignmentOperator + "\"" + fieldName2 + "\"" + nameSpace; } } if (xsdDatatype == "anyType") { xsdDatatype = ""; } else if (xsdDatatype != "") { xsdDatatype = ",DataType" + AttributeAssignmentOperator + "\"" + xsdDatatype + "\""; } if (particleOccurs > 1 || fieldOccurs > 1) { if (dotNetDatatype == "System.Xml.XmlElement") { //outStream.WriteLine(ElementAnyMaxOccursTemplate, fieldName1, fieldType, elementName, schemaForm, xsdDatatype, fieldName2, nameSpace, // hiddenMemberPrefix, isElementNullable.ToString().ToLower()); } else { generator.put_FieldCollectionTemplate(fieldType, elementName, elementName, default_value, is_required); //outStream.WriteLine(FieldCollectionTemplate, fieldName1, fieldType, elementName, schemaForm, fieldName1, xsdDatatype, nameSpace, // hiddenMemberPrefix, collectionSuffix, isElementNullable.ToString().ToLower(), fieldType); } } else { switch (dotNetDatatype) { // object type case "System.String": case "System.Byte[]": case "System.Object": case "System.Xml.XmlQualifiedName": generator.put_ElementObjectTemplate(fieldType, fieldName1, elementName, default_value, is_required); //outStream.WriteLine(ElementObjectTemplate, fieldName1, fieldType, elementName, schemaForm, xsdDatatype, fieldName2, nameSpace, // hiddenMemberPrefix, isElementNullable.ToString().ToLower()); break; // special xsd:any case "System.Xml.XmlElement": // assuming properly formatted nameSpace from above with Name and Namespace parameters //outStream.WriteLine(ElementAnyTemplate, fieldName1, fieldType, elementName, schemaForm, xsdDatatype, fieldName2, nameSpace, // hiddenMemberPrefix, isElementNullable.ToString().ToLower()); break; // value type case "System.DateTime": //outStream.WriteLine(ElementDateTimeTemplate, fieldName1, fieldType, elementName, schemaForm, xsdDatatype, fieldName2, nameSpace, // hiddenMemberPrefix); break; default: if (fieldType == "string") // value types like System.Uri { generator.put_ElementObjectTemplate(fieldType, fieldName1, elementName, default_value, is_required); } //outStream.WriteLine(ElementObjectTemplate, fieldName1, fieldType, elementName, schemaForm, xsdDatatype, fieldName2, nameSpace, // hiddenMemberPrefix, isElementNullable.ToString().ToLower()); else if (fieldType.StartsWith("OLI_LU_")) { generator.put_ElementValueTypeTemplate("int", fieldName1, elementName, default_value, is_required); } //outStream.WriteLine(ElementValueTypeTemplate, fieldName1, "int", elementName, schemaForm, xsdDatatype, fieldName2, nameSpace, //hiddenMemberPrefix); else { generator.put_ElementValueTypeTemplate(fieldType, fieldName1, elementName, default_value, is_required); } //outStream.WriteLine(ElementValueTypeTemplate, fieldName1, fieldType, elementName, schemaForm, xsdDatatype, fieldName2, nameSpace, //hiddenMemberPrefix); break; } } }
/// <summary> /// Add a field to the class that will persist itself to an attrbute /// </summary> /// <param name="outStream"></param> /// <param name="dotNetDatatype">.NET System datatype</param> /// <param name="xsdDatatype">XSD equivelent datatype</param> /// <param name="fieldName">Name of the attribute that will be a new field in code</param> /// <param name="dotnetFieldName">Name of the .net class field -- different from fieldName if duplicates occur</param> /// <param name="attributeFormDefault">whether the XML attribute name generated by the XmlSerializer is qualified</param> /// <param name="isSchemaEnumerationType">some languages like MC++ need to perform special logic if the field's type is an enumeration</param> /// <param name="ns">attribute namesapce</param> public virtual void ClassAttributeFieldCode(GeneratorStream generator, string dotNetDatatype, string xsdDatatype, string fieldName, string dotnetFieldName, XmlSchemaForm attributeFormDefault, bool isSchemaEnumerationType, string ns, string default_value, bool is_required) { string attributeName = fieldName; string fieldName1 = ReplaceInvalidChars(dotnetFieldName); string fieldName2 = CheckForKeywords(dotnetFieldName); string fieldType = ConvertSystemDatatype(dotNetDatatype); string nameSpace = ""; string schemaForm = ""; if (attributeFormDefault == XmlSchemaForm.Qualified || attributeFormDefault == XmlSchemaForm.Unqualified) { schemaForm = ",Form" + AttributeAssignmentOperator + "XmlSchemaForm." + attributeFormDefault.ToString(); nameSpace = CalculateNamespace(schemaTargetNamespace, ns, dotNetDatatype == "System.Xml.XmlAttribute[]"); } if (xsdDatatype == "anyType") { xsdDatatype = ""; } else if (xsdDatatype != "") { xsdDatatype = ",DataType" + AttributeAssignmentOperator + "\"" + xsdDatatype + "\""; } switch (dotNetDatatype) { // object type case "System.String": case "System.Byte[]": case "System.Object": case "System.Xml.XmlQualifiedName": generator.put_AttributeObjectTemplate(fieldType, fieldName1, attributeName, default_value, is_required); //outStream.WriteLine(AttributeObjectTemplate, fieldName1, fieldType, attributeName, schemaForm, xsdDatatype, fieldName2, nameSpace, // hiddenMemberPrefix); break; // special xsd:any case "System.Xml.XmlAttribute[]": //outStream.WriteLine(AttributeAnyTemplate, fieldName1, fieldType, attributeName, schemaForm, xsdDatatype, fieldName2, nameSpace, // hiddenMemberPrefix); break; // value type case "System.DateTime": //outStream.WriteLine(AttributeDateTimeTemplate, fieldName1, fieldType, attributeName, schemaForm, xsdDatatype, fieldName2, nameSpace, // hiddenMemberPrefix); break; default: if (fieldType == "string") // value types like System.Uri { generator.put_AttributeObjectTemplate(fieldType, fieldName1, attributeName, default_value, is_required); } //outStream.WriteLine(AttributeObjectTemplate, fieldName1, fieldType, attributeName, schemaForm, xsdDatatype, fieldName2, nameSpace, // hiddenMemberPrefix); else if (fieldType.StartsWith("OLI_LU_")) // special case for ACORD life { generator.put_AttributeValueTypeTemplate("int", fieldName1, attributeName, default_value, is_required); } //outStream.WriteLine(AttributeValueTypeTemplate, fieldName1, "int", attributeName, schemaForm, xsdDatatype, fieldName2, nameSpace, // hiddenMemberPrefix); else { generator.put_AttributeValueTypeTemplate(fieldType, fieldName1, attributeName, default_value, is_required); } //outStream.WriteLine(AttributeValueTypeTemplate, fieldName1, fieldType, attributeName, schemaForm, xsdDatatype, fieldName2, nameSpace, // hiddenMemberPrefix); break; } }
/// <summary> /// Close the class containing all of the generated type. Build a constructor if necessary to initialize fields. /// </summary> /// <param name="outStream"></param> /// <param name="dotnetClassName">Class name to generate</param> /// <param name="ctorList">Field list to build and initialize in a constructor</param> /// <param name="defaultInitialization">Build schema compliancy and initialization logic into class constructors</param> /// <param name="depthFirstTraversalHooks">Build DepthFirstTraversal events, to allow for client DepthFirstTraversal event handers and custom routines</param> /// <param name="makeSchemaCompliant">Add MakeSchemaCompliant function to each class to create all required child nodes</param> /// <param name="complexTypeBaseClass">Base class</param> /// <param name="baseClassIsMixed">Base class is mixed, so child can't be mixed -- otherwise XmlSerializer error</param> /// <param name="mixed">If the element has mixed content and can also have text</param> /// <param name="mixedType">Type of mixed content. Can be an empty string if mixed=false.</param> public abstract void ClassTrailerCode(GeneratorStream generator, string dotnetClassName, ArrayList ctorList, bool defaultInitialization, bool depthFirstTraversalHooks, bool makeSchemaCompliant, string complexTypeBaseClass, bool baseClassIsMixed, bool mixed, string mixedXsdType);