How to set a value to union?

Developer
Nov 5, 2009 at 10:38 AM

XSD:

	<xs:element name="account">
		<xs:complexType>
			<xs:sequence/>
			<xs:attribute name="x" type="type"/>
		</xs:complexType>
	</xs:element>

	<xs:simpleType name="type">
		<xs:union memberTypes="type1 type2" />
	</xs:simpleType>

	<xs:simpleType name="type1">
		<xs:restriction base="xs:string">
			<xs:pattern value="[0-9]+" />
		</xs:restriction>
	</xs:simpleType>

	<xs:simpleType name="type2">
		<xs:restriction base="xs:string">
			<xs:pattern value="[a-z]+" />
		</xs:restriction>
	</xs:simpleType>


C#:

var a = new A.account();
a.x = "a"; // here an exception.
What is the right way to set a.x?