SoapAttributeOverrides.Item プロパティ (Type)
指定された型 (基本クラス) に関連付けられているオブジェクトを取得します。
[C#] C# では、このプロパティは SoapAttributeOverrides クラスのインデクサになります。
Overloads Public Default ReadOnly Property Item( _
ByVal type As Type _) As SoapAttributes
[C#]
public SoapAttributes this[Typetype] {get;}
[C++]
public: __property SoapAttributes* get_Item(Type* type);
[JScript]
returnValue = SoapAttributeOverridesObject.Item(type);またはreturnValue = SoapAttributeOverridesObject(type);
[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。
引数 [JScript]
- type
取得する属性のコレクションに関連付けられている基本クラスのクラス Type 。
パラメータ [Visual Basic, C#, C++]
- type
取得する属性のコレクションに関連付けられている基本クラスのクラス Type 。
プロパティ値
オーバーライドする側の属性のコレクションを表す SoapAttributes 。
解説
SoapTypeAttribute の属性を格納している SoapAttributes を返すには、このオーバーロードを使用します。
使用例
[Visual Basic, C#, C++] Group
クラスのインスタンスのシリアル化をオーバーライドするために使用される SoapAttributeOverrides の作成例を次に示します。この例では、 Item プロパティを使用して、シリアル化のオーバーライドを指定するために使用される SoapAttributes の取得も行っています。
Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
' The name of this type will be overridden using
' the SoapTypeAttribute.
Public Class Group
Public GroupName As String
End Class
Public Class Run
Shared Sub Main()
Dim test As Run = new Run()
test.SerializeOverride("GetSoapAttributesVB2.xml")
End Sub
Public Sub SerializeOverride(filename As string )
' Create an instance of the XmlSerializer class
' that overrides the serialization.
Dim overrideSerializer As XmlSerializer = _
CreateOverrideSerializer()
' Writing the file requires a TextWriter.
Dim writer As TextWriter = new StreamWriter(filename)
' Create an instance of the class that will be serialized.
Dim myGroup As Group = new Group()
' Set the object properties.
myGroup.GroupName = ".NET"
' Serialize the class, and close the TextWriter.
overrideSerializer.Serialize(writer, myGroup)
writer.Close()
End Sub
Private Function CreateOverrideSerializer() As XmlSerializer
Dim mySoapAttributeOverrides As SoapAttributeOverrides = _
New SoapAttributeOverrides()
Dim mySoapAtts As SoapAttributes = new SoapAttributes()
Dim mySoapType As SoapTypeAttribute = _
new SoapTypeAttribute()
mySoapType.TypeName = "Team"
mySoapAtts.SoapType = mySoapType
' Add the SoapAttributes to the
' mySoapAttributeOverridesrides object.
mySoapAttributeOverrides.Add(GetType(Group), mySoapAtts)
' Get the SoapAttributes with the Item property.
Dim thisSoapAtts As SoapAttributes = _
mySoapAttributeOverrides(GetType(Group))
Console.WriteLine("New serialized type name: " & _
thisSoapAtts.SoapType.TypeName)
' Create an XmlTypeMapping that is used to create an instance
' of the XmlSerializer. Then return the XmlSerializer object.
Dim myMapping As XmlTypeMapping = _
(New SoapReflectionImporter(mySoapAttributeOverrides)). _
ImportTypeMapping(GetType(Group))
Dim ser As XmlSerializer = new XmlSerializer(myMapping)
return ser
End Function
End Class
[C#]
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
// The name of this type will be overridden using
// the SoapTypeAttribute.
public class Group
{
public string GroupName;
}
public class Run
{
public static void Main()
{
Run test = new Run();
test.SerializeOverride("GetSoapAttributes2.xml");
}
public void SerializeOverride(string filename)
{
// Create an instance of the XmlSerializer class
// that overrides the serialization.
XmlSerializer overRideSerializer = CreateOverrideSerializer();
// Writing the file requires a TextWriter.
TextWriter writer = new StreamWriter(filename);
// Create an instance of the class that will be serialized.
Group myGroup = new Group();
// Set the object properties.
myGroup.GroupName = ".NET";
// Serialize the class, and close the TextWriter.
overRideSerializer.Serialize(writer, myGroup);
writer.Close();
}
private XmlSerializer CreateOverrideSerializer()
{
SoapAttributeOverrides mySoapAttributeOverrides =
new SoapAttributeOverrides();
SoapAttributes mySoapAttributes = new SoapAttributes();
SoapTypeAttribute mySoapType = new SoapTypeAttribute();
mySoapType.TypeName= "Team";
mySoapAttributes.SoapType = mySoapType;
// Add the SoapAttributes to the
// mySoapAttributeOverridesrides object.
mySoapAttributeOverrides.Add(typeof(Group), mySoapAttributes);
// Get the SoapAttributes with the Item property.
SoapAttributes thisSoapAtts =
mySoapAttributeOverrides[typeof(Group)];
Console.WriteLine("New serialized type name: " +
thisSoapAtts.SoapType.TypeName);
// Create an XmlTypeMapping that is used to create an instance
// of the XmlSerializer. Then return the XmlSerializer object.
XmlTypeMapping myMapping = (new SoapReflectionImporter(
mySoapAttributeOverrides)).ImportTypeMapping(typeof(Group));
XmlSerializer ser = new XmlSerializer(myMapping);
return ser;
}
}
[C++]
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Serialization;
// The name of this type will be overridden using
// the SoapTypeAttribute.
__gc public class Group
{
public:
String* GroupName;
};
__gc public class Run
{
public:
void SerializeOverride(String* filename)
{
// Create an instance of the XmlSerializer class
// that overrides the serialization.
XmlSerializer * overRideSerializer = CreateOverrideSerializer();
// Writing the file requires a TextWriter.
TextWriter* writer = new StreamWriter(filename);
// Create an instance of the class that will be serialized.
Group* myGroup = new Group();
// Set the object properties.
myGroup -> GroupName = S".NET";
// Serialize the class, and close the TextWriter.
overRideSerializer -> Serialize(writer, myGroup);
writer -> Close();
}
private:
XmlSerializer * CreateOverrideSerializer()
{
SoapAttributeOverrides* mySoapAttributeOverrides = new SoapAttributeOverrides();
SoapAttributes* mySoapAttributes = new SoapAttributes();
SoapTypeAttribute* mySoapType = new SoapTypeAttribute();
mySoapType -> TypeName= S"Team";
mySoapAttributes -> SoapType = mySoapType;
// Add the SoapAttributes to the
// mySoapAttributeOverridesrides object.
mySoapAttributeOverrides -> Add(__typeof(Group), mySoapAttributes);
// Get the SoapAttributes with the Item property.
SoapAttributes * thisSoapAtts = mySoapAttributeOverrides->Item[__typeof(Group)];
Console::WriteLine(S"New serialized type name: {0}", thisSoapAtts -> SoapType -> TypeName);
// Create an XmlTypeMapping that is used to create an instance
// of the XmlSerializer. Then return the XmlSerializer object.
XmlTypeMapping * myMapping = (new SoapReflectionImporter(mySoapAttributeOverrides)) -> ImportTypeMapping(__typeof(Group));
XmlSerializer* ser = new XmlSerializer(myMapping);
return ser;
}
};
int main()
{
Run* test = new Run();
test -> SerializeOverride(S"GetSoapAttributes2.xml");
}
[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 ファミリ
参照
SoapAttributeOverrides クラス | SoapAttributeOverrides メンバ | System.Xml.Serialization 名前空間 | SoapAttributeOverrides.Item オーバーロードの一覧