XmlElementAttribute.IsNullable 屬性

定義

取得或設定值,指出 XmlSerializer 是否必須將設為 null 的成員序列化為 xsi:nil 屬性設為 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,否則為 false

範例

下列範例顯示已套用 的 XmlElementAttribute 欄位,並將 IsNullable 屬性設定為 false

public ref class MyClass
{
public:

   [XmlElement(IsNullable=false)]
   String^ Group;
};
public class MyClass
{
   [XmlElement(IsNullable = false)]
   public string Group;
}
Public Class MyClass1
    <XmlElement(IsNullable := False)> Public Group As String
End Class

備註

結構的 XML 架構規格可讓 XML 檔明確表示元素的內容遺失。 這類專案包含設定為 true 的屬性 xsi:nil 。 如需詳細資訊,請參閱全球資訊網協會規格 XML 架構第 1 部分:結構

IsNullable如果 屬性設定為 true ,則會針對已設定 null 為 的 xsi:nil 類別成員產生 屬性。 例如,如果您將名為 MyStringArray 的欄位設定為 null ,則 XmlSerializer 會產生下列 XML 程式碼。

<MyStringArray xsi:nil = "true" />  

IsNullable如果 屬性為 false ,則不會針對已設定 null 為 的類別成員產生任何 XML 專案。

注意

您無法將 IsNullable 屬性套用至型別為實值型別的成員,因為實值型別不能包含 null 。 此外,您無法將此屬性設定為 false 可為 Null 的實值型別。 當這類類型為 null 時,會藉由將 設定 xsi:niltrue 來序列化。

適用於