2013-04-22 1 views
1

이 버그입니까?Xsd.exe가 열거 형을 상속 할 때 잘못된 C# 클래스를 생성합니다.

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <xsd:simpleType name="sbrSexItemType"> 
      <xsd:restriction base="xsd:string"> 
       <xsd:enumeration value="1"/> 
       <xsd:enumeration value="2"/> 
       <xsd:enumeration value="3"/> 
       <xsd:enumeration value="0"/> 
      </xsd:restriction> 
    </xsd:simpleType> 
    <xsd:element name="TestSexItemType1" type="sbrSexItemType"/> 
    <xsd:element name="TestSexItemType2" type="sbrSexItemType"/> 
</xsd:schema> 

내가 얻을 :

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")] 
[System.SerializableAttribute()] 
[System.Xml.Serialization.XmlRootAttribute("TestSexItemType1", Namespace="", IsNullable=false)] 
public enum sbrSexItemType { 

    /// <remarks/> 
    [System.Xml.Serialization.XmlEnumAttribute("1")] 
    Item1, 

    /// <remarks/> 
    [System.Xml.Serialization.XmlEnumAttribute("2")] 
    Item2, 

    /// <remarks/> 
    [System.Xml.Serialization.XmlEnumAttribute("3")] 
    Item3, 

    /// <remarks/> 
    [System.Xml.Serialization.XmlEnumAttribute("0")] 
    Item0, 
} 

이 농담의 일종인가요? 오류조차 발생하지 않았습니다. 생성 된 코드는 어떤 모양이나 형태의 XSD를 어떻게 나타 냅니까?

답변

1

물론 가능한 값 1,2,3,0을 열거 형 값으로 직접 변환 할 수 없습니다 (식별자는 숫자로 시작할 수 없습니다). 따라서 xsd는 식별자를 생성 할 때 값 앞에 "Item"을 넣습니다. XmlEnumAttributeXmlSerializer에게 Xml 파일을 읽거나 쓸 때 실제로 사용할 값을 알려줍니다. 생성 된 enum이 작업을 수행하는 것처럼 보입니다.

+0

아니요, 요점은 "TestSexItemType1"유형을 생성하는 대신 열거 형을 생성하고 유형을 "닮은"루트 요소를 지정합니다. 그렇다면 "TestSexItemType2"를 완전히 무시합니다. ... –

+0

@SleeperSmith 전체 xsd에 대한 클래스가 있어야합니다. 어떻게 생겼어? – Botz3000

+0

아니요. 그게 다야. –

0

열거 형이 아닌 다른 유형이있는 경우 열거 형을 맨 위에 놓아야합니다. 왜 그런지 모르지만 내 문제는 그렇게 해결되었습니다.

+0

제안 해 주셔서 감사합니다. 열거 형을 상속 한 두 가지 유형을 넣었습니다. 여전히 운이 없습니다. –

관련 문제