Laden...

XMLObjectGen und NULL

Erstellt von Seikilos vor 13 Jahren Letzter Beitrag vor 13 Jahren 582 Views
S
Seikilos Themenstarter:in
753 Beiträge seit 2006
vor 13 Jahren
XMLObjectGen und NULL

Ich habe folgende XSD:

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <xsd:complexType name="A">
      <xsd:sequence>
         <xsd:element name="GroupedWith" type="Position"  nillable="true" />
      </xsd:sequence>
   </xsd:complexType>

   <xsd:complexType name="Position">
      <xsd:sequence>
      </xsd:sequence>
   </xsd:complexType>

</xsd:schema>


Im Endeffekt ist ein Knoten "Position" ein Element von A.
Nun generiere ich mir die C#Klasse daraus und habe bei dem GroupedWith aber das Problem, dass ich niemals ein null bekommen kann.


[XmlElement(Type=typeof(Position),ElementName="GroupedWith",IsNullable=false)]
		[EditorBrowsable(EditorBrowsableState.Advanced)]
		public Position __GroupedWith;
		
		[XmlIgnore]
		public Position GroupedWith
		{
			get
			{
				if (__GroupedWith == null) __GroupedWith = new Position();		
				return __GroupedWith;
			}
			set {__GroupedWith = value;}
		}

XSDObjectGen generiert mir bei dem getter automatisch ein new, wenn null.
Das ist aber absolut nicht das, was ich will. Ich erwarte dort null. Sprich wenn keine gruppierung vorhanden ist, soll ich auf keien Fall ein Objekt erzeugt bekommen.
Nun bekomme ich aber XSDObjectGen nicht dazu, einfach __GroupedWith zu returnen, ohne da die == null abfrage zu machen.

Ich habe bereits imXML Versucht dem GroupedWith ein "nillable=true" zu vergeben, ohne erfolg

Life is a short