No code generation for restriction-derived class elements

Dec 11, 2010 at 1:20 PM

Hi,

I want to generate code for the following two types TestBase and TestDerived, which mainly differ in their element default values:



<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Test"
    targetNamespace="http://test.net/Test.xsd"
    elementFormDefault="qualified"
    xmlns="http://test.net/Test.xsd"
    xmlns:mstns="http://test.net/Test.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:complexType name="TestBase">
    <xs:sequence>
      <xs:element name="TestElement1" type="xs:int" default="1"/>
      <xs:element name="TestElement2" type="xs:int"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="TestDerived">
    <xs:complexContent>
      <xs:restriction base="TestBase">
        <xs:sequence>
          <xs:element name="TestElement1" type="xs:int" default="5"/>
          <xs:element name="TestElement2" type="xs:int" default="2"/>
        </xs:sequence>
      </xs:restriction>
    </xs:complexContent>
  </xs:complexType>

</xs:schema>

What I get looks as follows:
namespace myNamespace{
    using System;
    using System.Diagnostics;
    using System.Xml.Serialization;
    using System.Collections;
    using System.Xml.Schema;
    using System.ComponentModel;
    using System.Collections.ObjectModel;
    
    
    /// <remarks/>
    [System.Xml.Serialization.XmlIncludeAttribute(typeof(TestDerived))]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://test.net/Test.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="http://test.net/Test.xsd", IsNullable=true)]
    public partial class TestBase {
        
        [EditorBrowsable(EditorBrowsableState.Never)]
        private int testElement1Field;
        
        [EditorBrowsable(EditorBrowsableState.Never)]
        private int testElement2Field;
        
        /// <summary>
        /// Initialisiert ein neues <c>TestBase</c>-Objekt mit Standardwerten.
        /// </summary>
        public TestBase() {
            this.testElement1Field = 1;
        }
        
        /// <remarks/>
        public int TestElement1 {
            get {
                return this.testElement1Field;
            }
            set {
                this.testElement1Field = value;
            }
        }
        
        /// <remarks/>
        public int TestElement2 {
            get {
                return this.testElement2Field;
            }
            set {
                this.testElement2Field = value;
            }
        }
    }
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://test.net/Test.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="http://test.net/Test.xsd", IsNullable=true)]
    public partial class TestDerived : TestBase {
    }
}

I would have expected, that a constructor is added for the TestDerived class, since it has different default values to set. So what I would expect looks as follows:
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://test.net/Test.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "http://test.net/Test.xsd", IsNullable = true)]
    public partial class TestDerived : TestBase
    {
        public TestDerived()
            : base()
        {
            this.TestElement1 = 5;
            this.TestElement2 = 2;
        }
    }

Anyone out there who can tell me if this is possible somehow and how I can get there?
Thx a lot, Chris