XmlTextAttribute Serializer Bug?

Mar 14, 2011 at 2:23 PM

I have a Xsd Schema that looks like this:

<xs:element minOccurs="0" name="Rate1">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="Unit" type="xs:string" use="required" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

Xsd2Code generates this code for the XmlText:

 [System.Xml.Serialization.XmlTextAttribute()]
        public string Value
        {
            get
            {
                return this.valueField;
            }
            set
            {
                if ((this.valueField != null))
                {
                    if ((valueField.Equals(value) != true))
                    {
                        this.valueField = value;
                        this.OnPropertyChanged("Value");
                    }
                }
                else
                {
                    this.valueField = value;
                    this.OnPropertyChanged("Value");
                }
            }
        }

This works fine for deserialization but when I serialize the same object the Value is not written as XmlText. After looking into this problem for an hour I found out that when I change the member from "Value" to "Text" everything works perfect. It seems like the .net serializer is ignoring the XmlTextAttribute and only looks for a member "Text". 

[System.Xml.Serialization.XmlTextAttribute()]
public string Text 

After changing all generated code to this everything is working.

And now my Questions:

  1. Is there a better way of solving this? Like a xsd2code flag that I missed?
  2. If there is no better way could this be integrated in the next Version of xsd2code ? :-)