Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 IsNullable Property

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
XmlElementAttribute..::.IsNullable Property

Gets or sets a value that indicates whether the XmlSerializer must serialize a member that is set to nullNothingnullptra 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)
Visual Basic (Declaration)
Public Property IsNullable As Boolean
Visual Basic (Usage)
Dim instance As XmlElementAttribute
Dim value As Boolean

value = instance.IsNullable

instance.IsNullable = value
C#
public bool IsNullable { get; set; }
Visual C++
public:
property bool IsNullable {
    bool get ();
    void set (bool value);
}
JScript
public function get IsNullable () : boolean
public function set IsNullable (value : boolean)

Property Value

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

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 nullNothingnullptra null reference (Nothing in Visual Basic). For example if you set a field named MyStringArray to nullNothingnullptra 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 nullNothingnullptra 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 nullNothingnullptra null reference (Nothing in Visual Basic). Additionally, you cannot set this property to false for nullable value types. When such types are nullNothingnullptra null reference (Nothing in Visual Basic), they will be serialized by setting xsi:nil to true.

The following example shows a field with the XmlElementAttribute applied to it, and the IsNullable property set to false.

Visual Basic
Public Class MyClass1
    <XmlElement(IsNullable := False)> Public Group As String
End Class


C#
public class MyClass
{
   [XmlElement(IsNullable = false)]
   public string Group;
}


Visual C++
public ref class MyClass
{
public:

   [XmlElement(IsNullable=false)]
   String^ Group;
};


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker