XmlArrayAttribute.IsNullable 属性

定义

获取或设置一个值,该值指示 XmlSerializer 是否必须将成员序列化为 xsi:nil 属性设置为 true 的 XML 空标记。Gets or sets a value that indicates whether the XmlSerializer must serialize a member as an empty XML tag with the xsi:nil attribute set to true.

public:
 property bool IsNullable { bool get(); void set(bool value); };
public bool IsNullable { get; set; }
member this.IsNullable : bool with get, set
Public Property IsNullable As Boolean

属性值

Boolean

如果 XmlSerializer 生成 true 属性,则为 xsi:nil;否则为 falsetrue if the XmlSerializer generates the xsi:nil attribute; otherwise, false.

示例

下面的示例包含两个数组:一个 IsNullable 属性设置为 true ,另一个的 IsNullable 属性设置为 falseThe following example contains two arrays: one with the IsNullable property set to true, and another with the IsNullable property set to false.

public ref class MyClass
{
public:

   [XmlArray(IsNullable=true)]
   array<String^>^IsNullableIsTrueArray;

   [XmlArray(IsNullable=false)]
   array<String^>^IsNullableIsFalseArray;
};

public class MyClass
{
   [XmlArray (IsNullable = true)]
   public string [] IsNullableIsTrueArray;

   [XmlArray (IsNullable = false)]
   public string [] IsNullableIsFalseArray;
}

Public Class MyClass1
    <XmlArray(IsNullable := True)> _
    Public IsNullableIsTrueArray() As String

    <XmlArray(IsNullable := False)> _
    Public IsNullableIsFalseArray() As String
End Class

注解

结构的 XML 架构规范允许 XML 文档显式通知缺少某个元素的内容。The XML schema specification for structures allows an XML document to explicitly signal that an element's content is missing. 此类元素包含将特性 xsi:nil 设置为 trueSuch an element contains the attribute xsi:nil set to true. 有关详细信息,请参阅名为 XML 架构第1部分:结构的万维网联合会规范。For more information, see the World Wide Web Consortium specification titled XML Schema Part 1: Structures.

如果将 IsNullable 属性设置为 true ,则 xsi:nil 为已设置为的类成员生成属性 nullIf the IsNullable property is set to true, the xsi:nil attribute is generated for class members that have been set to null. 例如,如果将名为的字段设置 MyStringArraynull ,则会 XmlSerializer 生成以下 XML 代码。For example, if you set a field named MyStringArray to null, the XmlSerializer generates the following XML code.

<MyStringArray xsi:nil = "true" />  

如果 IsNullable 属性为 false ,则不生成 XML 元素。If the IsNullable property is false, no XML element is generated.

备注

不能将属性应用于 IsNullable 类型为值类型的成员,因为值类型不能包含 nullYou cannot apply the IsNullable property to a member typed as a value type because a value type cannot contain null.

适用于