XmlAttributeOverrides.Item プロパティ (Type)
指定された (基本クラス) 型に関連付けられたオブジェクトを取得します。
[C#] C# では、このプロパティは XmlAttributeOverrides クラスのインデクサになります。
Overloads Public Default ReadOnly Property Item( _
ByVal type As Type _) As XmlAttributes
[C#]
public XmlAttributes this[Typetype] {get;}
[C++]
public: __property XmlAttributes* get_Item(Type* type);
[JScript]
returnValue = XmlAttributeOverridesObject.Item(type);またはreturnValue = XmlAttributeOverridesObject(type);
[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。
引数 [JScript]
- type
取得する属性のコレクションに関連付けられている基本クラスのクラス Type 。
パラメータ [Visual Basic, C#, C++]
- type
取得する属性のコレクションに関連付けられている基本クラスのクラス Type 。
プロパティ値
オーバーライドする側の属性のコレクションを表す XmlAttributes 。
解説
このオーバーロードを使用して XmlRootAttribute オブジェクトまたは XmlTypeAttribute オブジェクトの属性を含む XmlAttributes オブジェクトを返します。
XmlAttributes オブジェクトに XmlArrayAttribute 、 XmlArrayItemAttribute 、 XmlElementAttribute 、 XmlEnumAttribute 、または XmlAttributeAttribute をオーバーライドするオブジェクトが含まれている場合は、オーバーライドされるメンバと型の両方を指定するオーバーロードを使用する必要があります。
使用例
[Visual Basic, C#, C++] XmlAttributeOverrides オブジェクト、 XmlAttributes オブジェクト、および XmlRootAttribute オブジェクトを作成する例を次に示します。この例では、 XmlRootAttribute を XmlAttributes オブジェクトの XmlRoot プロパティに代入し、 XmlAttributes オブジェクトを XmlAttributeOverrides オブジェクトに追加します。最後にこの例では、シリアル化されたクラスの Type を XmlAttributeOverrides オブジェクトに渡すことにより XmlAttributes オブジェクトを取得します。この例では、 Type は Group です。
' 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
[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.
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;
}
}
[C++]
// This is the class that will be serialized.
public __gc class Group
{
public:
String* GroupName;
[XmlAttributeAttribute]
int GroupCode;
};
public __gc 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 = S"http://www.cpandl.com";
xRoot->ElementName = S"NewGroup";
attrs->XmlRoot = xRoot;
xOver->Add(__typeof(Group), attrs);
// Get the XmlAttributes object, based on the type.
XmlAttributes* tempAttrs;
tempAttrs = xOver->Item[__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;
}
};
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
XmlAttributeOverrides クラス | XmlAttributeOverrides メンバ | System.Xml.Serialization 名前空間 | XmlAttributeOverrides.Item オーバーロードの一覧 | XmlAttributes | XmlSerializer