如何使用MS XSD实用程序生成的类为复杂类型的属性赋值?

时间:2011-12-12 14:34:12

标签: c# xsd xsd.exe

我的XSD文件中有以下代码:

<xs:complexType name="CONSIDERATION" mixed="true">
        <xs:complexContent mixed="true">
            <xs:restriction base="xs:anyType">
                <xs:attribute name="_Description" type="xs:anySimpleType"/>
                <xs:attribute name="_Type" type="xs:anySimpleType" use="required"/>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>

我正在使用Microsoft XSD实用程序来生成强类型类。现在,当我想分配“_Description”和“_Type”时,我在类中找不到这些属性。生成的类具有以下代码:

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.1432")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
    public partial class CONSIDERATION {

        private string[] textField;

        /// <remarks/>
        [System.Xml.Serialization.XmlTextAttribute()]
        public string[] Text {
            get {
                return this.textField;
            }
            set {
                this.textField = value;
            }
        }
    }

只有Text属性可以为其赋值。如何为属性描述赋值并键入?

1 个答案:

答案 0 :(得分:0)

我不确定XSD.exe是否支持mixed =“true”类型(mixins?)。您应该尝试查看从其​​类型层次结构定义中具有CONSIDERATION的类型生成的内容。也许你会在那里找到你的田地。 这是类型系统阻抗不匹配的情况,因为架构试图定义的概念与.NET类型系统(单继承)不匹配。试着让你围绕<xs:restriction base="xs:anyType">并从.NET的角度来看它应该是什么意思:)。