SoapElementAttribute.IsNullable Property

Definition

Gets or sets a value that indicates whether the XmlSerializer must serialize a member that has the xsi:null attribute set to "1".

C#
public bool IsNullable { get; set; }

Property Value

true if the XmlSerializer generates the xsi:null 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:null set to "1". For more information, see the World Wide Web Consortium specification named XML Schema Part 1: Structures.

If the IsNullable property is set to true, the xsi:null attribute is generated for class members that have been set to null. For example, if you set a field named MyStringArray to null, the XmlSerializer generates the following XML code.

<MyStringArray xsi:null = "1" />  

If the IsNullable property is false, no XML element is generated.

Note

You cannot apply the IsNullable property to a member typed as a value type because a value type cannot contain null.

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1