XmlAttributeOverrides.Item プロパティ
オーバーライドする側の属性のコレクションを表すオブジェクトを取得します。
[C#] C# では、このプロパティは XmlAttributeOverrides クラスのインデクサになります。
オーバーロードの一覧
指定された (基本クラス) 型に関連付けられたオブジェクトを取得します。
[Visual Basic] Overloads Public Default ReadOnly Property Item(Type) As XmlAttributes
[JScript] XmlAttributeOverrides.Item (Type)
指定された (基本クラス) 型に関連付けられたオブジェクトを取得します。メンバ パラメータは、オーバーライドされた基本クラス メンバを指定します。
[Visual Basic] Overloads Public Default ReadOnly Property Item(Type, String) As XmlAttributes
[C++] public: __property XmlAttributes* get_Item(Type*, String*);
使用例
[Visual Basic, C#, C++] XmlAttributeOverrides オブジェクト、 XmlAttributes オブジェクト、および XmlAttributeAttribute オブジェクトを作成する例を次に示します。この例では、 XmlAttributeAttribute を XmlAttributes オブジェクトの XmlAttribute プロパティに代入し、 XmlAttributes オブジェクトを XmlAttributeOverrides オブジェクトに追加します。最後にこの例では、シリアル化されたクラスの Type 、およびメンバ名を XmlAttributeOverrides オブジェクトに渡すことにより XmlAttributes オブジェクトを取得します。
[Visual Basic, C#, C++] メモ ここでは、Item プロパティ (XmlAttributeOverrides インデクサ) のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
' 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
[C#]
// 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;
}
}
[C++]
// This is the class that will be serialized.
public __gc class Group
{
public:
String* GroupName;
public:
[XmlAttributeAttribute]
int GroupCode;
};
public __gc 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 = S"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), S"GroupCode", attrs);
// Get the XmlAttributes object for the type and member.
XmlAttributes* tempAttrs;
tempAttrs = xOver->get_Item(__typeof(Group), S"GroupCode");
Console::WriteLine(tempAttrs->XmlAttribute->AttributeName);
// Create the XmlSerializer instance and return it.
XmlSerializer* xSer = new XmlSerializer(__typeof(Group), xOver);
return xSer;
}
};
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
参照
XmlAttributeOverrides クラス | XmlAttributeOverrides メンバ | System.Xml.Serialization 名前空間