Anton
Anton

Reputation: 1030

svcutil.exe xsd code generation for objects with nested arrays

I've got and XSD which I use to generate DataContracts for my WCF service. Here is visual represantation of XSD

XSD visual representation

When i use XSD.EXE for generation everything is fine and i get object like so

    public partial class MessageType {

    private MessageInfoType messageInfoField;

    private LotType[] lotsListField;

    /// <remarks/>
    public MessageInfoType messageInfo {
        get {
            return this.messageInfoField;
        }
        set {
            this.messageInfoField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayItemAttribute("lot", IsNullable=false)]
    public LotType[] lotsList {
        get {
            return this.lotsListField;
        }
        set {
            this.lotsListField = value;
        }
    }
}

And here is generated code for nested lot object

    public partial class LotType {

    private LotGeneralInfoType lotGeneralInfoField;

    private ProductInfoType[] productInfoField;

    //Other generated fields

}

but when I try to generated classes via svcutil.exe with command

svcutil *.xsd /dconly /ser:XmlSerializer /importXmlTypes

I get different result. Here is generated code for MessageType object.

    [System.Runtime.Serialization.DataContractAttribute(Name="MessageType", Namespace="http://test.me/types")]
public partial class MessageType : object, System.Runtime.Serialization.IExtensibleDataObject
{

    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;

    private MessageInfoType messageInfoField;

    private LotsListType lotsListField;

    public System.Runtime.Serialization.ExtensionDataObject ExtensionData
    {
        get
        {
            return this.extensionDataField;
        }
        set
        {
            this.extensionDataField = value;
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true, EmitDefaultValue=false)]
    public MessageInfoType messageInfo
    {
        get
        {
            return this.messageInfoField;
        }
        set
        {
            this.messageInfoField = value;
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true, EmitDefaultValue=false, Order=1)]
    public LotsListType lotsList
    {
        get
        {
            return this.lotsListField;
        }
        set
        {
            this.lotsListField = value;
        }
    }
}

It's look like that everything is ok but nested LotType array is different. It represents collection with some kind of xml elements with it. Here is the generated code

[System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
    [System.Runtime.Serialization.CollectionDataContractAttribute(Name="LotsListType", Namespace="http://test.me/types", ItemName="lot")]
    public class LotsListType : System.Collections.Generic.List<LotType>
    {
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
    [System.Xml.Serialization.XmlSchemaProviderAttribute("ExportSchema")]
    [System.Xml.Serialization.XmlRootAttribute(IsNullable=false)]
    public partial class LotType : object, System.Xml.Serialization.IXmlSerializable
    {

        private System.Xml.XmlNode[] nodesField;

        private static System.Xml.XmlQualifiedName typeName = new System.Xml.XmlQualifiedName("LotType", "http://test.me/types");

        public System.Xml.XmlNode[] Nodes
        {
            get
            {
                return this.nodesField;
            }
            set
            {
                this.nodesField = value;
            }
        }

        public void ReadXml(System.Xml.XmlReader reader)
        {
            this.nodesField = System.Runtime.Serialization.XmlSerializableServices.ReadNodes(reader);
        }

        public void WriteXml(System.Xml.XmlWriter writer)
        {
            System.Runtime.Serialization.XmlSerializableServices.WriteNodes(writer, this.Nodes);
        }

        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
        }

        public static System.Xml.XmlQualifiedName ExportSchema(System.Xml.Schema.XmlSchemaSet schemas)
        {
            System.Runtime.Serialization.XmlSerializableServices.AddDefaultSchema(schemas, typeName);
            return typeName;
        }
    }

Is there any way to generated just the same code like XSD.EXE but with DataMemeber/DataContract attributes?

Upvotes: 1

Views: 466

Answers (0)

Related Questions