共用方式為


XmlAttributeOverrides.Item[] 屬性

定義

取得一個代表覆蓋屬性集合的物件。

多載

名稱 Description
Item[Type]

取得與指定基底類別型別相關聯的物件。

Item[Type, String]

取得與指定(基底類別)類型相關的物件。 成員參數指定被覆寫的基底類別成員。

Item[Type]

來源:
XmlAttributeOverrides.cs
來源:
XmlAttributeOverrides.cs
來源:
XmlAttributeOverrides.cs
來源:
XmlAttributeOverrides.cs
來源:
XmlAttributeOverrides.cs

取得與指定基底類別型別相關聯的物件。

public:
 property System::Xml::Serialization::XmlAttributes ^ default[Type ^] { System::Xml::Serialization::XmlAttributes ^ get(Type ^ type); };
public System.Xml.Serialization.XmlAttributes this[Type type] { get; }
public System.Xml.Serialization.XmlAttributes? this[Type type] { get; }
member this.Item(Type) : System.Xml.Serialization.XmlAttributes
Default Public ReadOnly Property Item(type As Type) As XmlAttributes

參數

type
Type

與你想要取得的屬性集合相關聯的基底類別 Type

屬性值

代表 XmlAttributes 一組覆蓋屬性的集合。

範例

以下範例會產生一個 XmlAttributeOverrides 物件、一個 XmlAttributes 物件、再一個 XmlRootAttribute 物件。 範例將 指派到 物件XmlRootAttributeXmlAttributes屬性,並將物件加入XmlAttributes物件XmlAttributeOverridesXmlRoot 最後,範例透過將序列化類別的 傳遞Type給物件XmlAttributeOverrides來取得XmlAttributes物件。 在此範例中,TypeGroup

// This is the class that will be serialized.
public class Group
{
   public string GroupName;
   [XmlAttribute]
   public int GroupCode;
}

public class Sample
{
public XmlSerializer CreateOverrider()
{
   // Create an XmlSerializer with overriding attributes.
   XmlAttributes attrs = new XmlAttributes();
   XmlAttributeOverrides xOver = new XmlAttributeOverrides();

   XmlRootAttribute xRoot = new XmlRootAttribute();
   // Set a new Namespace and ElementName for the root element.
   xRoot.Namespace = "http://www.cpandl.com";
   xRoot.ElementName = "NewGroup";
   attrs.XmlRoot = xRoot;

   xOver.Add(typeof(Group), attrs);

   // Get the XmlAttributes object, based on the type.
   XmlAttributes tempAttrs;
   tempAttrs = xOver[typeof(Group)];

   // Print the Namespace and ElementName of the root.
   Console.WriteLine(tempAttrs.XmlRoot.Namespace);
   Console.WriteLine(tempAttrs.XmlRoot.ElementName);

   XmlSerializer xSer = new XmlSerializer(typeof(Group), xOver);
   return xSer;
}
}
' This is the class that will be serialized.
Public Class Group
    Public GroupName As String
    <XmlAttribute()> Public GroupCode As Integer
End Class

Public Class Sample
    
    Public Function CreateOverrider() As XmlSerializer
        ' Create an XmlSerializer with overriding attributes.
        Dim attrs As New XmlAttributes()
        Dim xOver As New XmlAttributeOverrides()
        
        Dim xRoot As New XmlRootAttribute()
        ' Set a new Namespace and ElementName for the root element.
        xRoot.Namespace = "http://www.cpandl.com"
        xRoot.ElementName = "NewGroup"
        attrs.XmlRoot = xRoot
        
        xOver.Add(GetType(Group), attrs)
        
        ' Get the XmlAttributes object, based on the type.
        Dim tempAttrs As XmlAttributes
        tempAttrs = xOver(GetType(Group))
        
        ' Print the Namespace and ElementName of the root.
        Console.WriteLine(tempAttrs.XmlRoot.Namespace)
        Console.WriteLine(tempAttrs.XmlRoot.ElementName)
        
        Dim xSer As New XmlSerializer(GetType(Group), xOver)
        Return xSer
    End Function
End Class

備註

利用此過載回XmlAttributes傳包含某個或XmlTypeAttribute物件屬性XmlRootAttribute的物件。

如果XmlAttributes物件包含覆蓋 XmlArrayAttributeXmlArrayItemAttributeXmlElementAttributeXmlEnumAttribute、 或 XmlAttributeAttribute的物件,你必須使用指定被覆寫成員及型別的超載。

另請參閱

適用於

Item[Type, String]

來源:
XmlAttributeOverrides.cs
來源:
XmlAttributeOverrides.cs
來源:
XmlAttributeOverrides.cs
來源:
XmlAttributeOverrides.cs
來源:
XmlAttributeOverrides.cs

取得與指定(基底類別)類型相關的物件。 成員參數指定被覆寫的基底類別成員。

public:
 property System::Xml::Serialization::XmlAttributes ^ default[Type ^, System::String ^] { System::Xml::Serialization::XmlAttributes ^ get(Type ^ type, System::String ^ member); };
public System.Xml.Serialization.XmlAttributes this[Type type, string member] { get; }
public System.Xml.Serialization.XmlAttributes? this[Type type, string member] { get; }
member this.Item(Type * string) : System.Xml.Serialization.XmlAttributes
Default Public ReadOnly Property Item(type As Type, member As String) As XmlAttributes

參數

type
Type

就是與你想要的屬性集合相關聯的基底類別 Type

member
String

指定 to return 的 XmlAttributes 覆寫成員名稱。

屬性值

代表 XmlAttributes 一組覆蓋屬性的集合。

範例

以下範例會產生一個XmlAttributeOverrides物件、一個、XmlAttributeAttribute一個XmlAttributes物件。 範例將 賦予XmlAttributeAttributeXmlAttribute物件的XmlAttributes屬性,並將物件加入XmlAttributes物件XmlAttributeOverrides。 最後,範例透過將序列化類別的 與Type成員名稱傳遞給XmlAttributeOverrides物件,取得XmlAttributes物件。

// This is the class that will be serialized.
public class Group
{
   public string GroupName;
   [XmlAttribute]
   public int GroupCode;
}

public class Sample
{
public XmlSerializer CreateOverrider()
{
   // Create an XmlSerializer with overriding attributes.
   XmlAttributeOverrides xOver = new XmlAttributeOverrides();

   /* Create an XmlAttributeAttribute object and set the
   AttributeName property. */
   XmlAttributeAttribute xAtt = new XmlAttributeAttribute();
   xAtt.AttributeName = "Code";

   /* Create a new XmlAttributes object and set the
   XmlAttributeAttribute object to the XmlAttribute property. */
   XmlAttributes attrs = new XmlAttributes();
   attrs.XmlAttribute = xAtt;

   /* Add the XmlAttributes to the XmlAttributeOverrides object. The
   name of the overridden attribute must be specified. */
   xOver.Add(typeof(Group), "GroupCode", attrs);

   // Get the XmlAttributes object for the type and member.
   XmlAttributes tempAttrs;
   tempAttrs = xOver[typeof(Group), "GroupCode"];
   Console.WriteLine(tempAttrs.XmlAttribute.AttributeName);

   // Create the XmlSerializer instance and return it.
   XmlSerializer xSer = new XmlSerializer(typeof(Group), xOver);
   return xSer;
}
}
' This is the class that will be serialized.
Public Class Group
    Public GroupName As String
    <XmlAttribute()> Public GroupCode As Integer
End Class

Public Class Sample
    
    Public Function CreateOverrider() As XmlSerializer
        ' Create an XmlSerializer with overriding attributes.
        Dim xOver As New XmlAttributeOverrides()
        
        ' Create an XmlAttributeAttribute object and set the
        ' AttributeName property. 
        Dim xAtt As New XmlAttributeAttribute()
        xAtt.AttributeName = "Code"
        
        ' Create a new XmlAttributes object and set the
        ' XmlAttributeAttribute object to the XmlAttribute property. 
        Dim attrs As New XmlAttributes()
        attrs.XmlAttribute = xAtt
        
        ' Add the XmlAttributes to the XmlAttributeOverrides object. The
        ' name of the overridden attribute must be specified. 
        xOver.Add(GetType(Group), "GroupCode", attrs)
                
        ' Get the XmlAttributes object for the type and member.
        Dim tempAttrs As XmlAttributes
        tempAttrs = xOver(GetType(Group), "GroupCode")
        Console.WriteLine(tempAttrs.XmlAttribute.AttributeName)
        
        ' Create the XmlSerializer instance and return it.
        Dim xSer As New XmlSerializer(GetType(Group), xOver)
        Return xSer
    End Function
End Class

備註

利用此過載回XmlAttributes傳包含覆蓋 XmlArrayAttributeXmlArrayItemAttributeXmlAttributeAttributeXmlElementAttribute、 或 XmlEnumAttribute的物件的物件。 若 XmlAttributes 物件包含 XmlRootAttributeXmlTypeAttribute,則必須使用僅指定覆寫型態的超載。

另請參閱

適用於