Compartilhar via


XmlElementAttribute.IsNullable Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets a value that indicates whether the XmlSerializer must serialize a member that is set to nulla null reference (Nothing in Visual Basic) as an empty tag with the xsi:nil attribute set to true.

Namespace:  System.Xml.Serialization
Assembly:  System.Xml (in System.Xml.dll)

Syntax

'Declaration
Public Property IsNullable As Boolean
public bool IsNullable { get; set; }

Property Value

Type: System.Boolean
true if the XmlSerializer generates the xsi:nil attribute; otherwise, false.

Remarks

The XML schema specification for structures allows an XML document to explicitly signal that an element's content is missing. Such an element contains the attribute xsi:nil set to true.

For more information, see

the World Wide Web Consortium (www.w3.org) specification, XML Schema Part 1: Structures.

If the IsNullable property is set to true, the xsi:nil attribute is generated for class members that have been set to nulla null reference (Nothing in Visual Basic). For example, if you set a field named MyStringArray to nulla null reference (Nothing in Visual Basic), the XmlSerializer generates the following XML code.

 <MyStringArray xsi:nil = "true" />

If the IsNullable property is false, no XML element is generated for class members that have been set to nulla null reference (Nothing in Visual Basic).

NoteNote:

You cannot apply the IsNullable property to a member typed as a value type because a value type cannot contain nulla null reference (Nothing in Visual Basic). Additionally, you cannot set this property to false for value types that can be nulla null reference (Nothing in Visual Basic). When such types are nulla null reference (Nothing in Visual Basic), they are serialized by setting xsi:nil to true.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.