次の方法で共有


XmlAttributeOverrides.Item[] プロパティ

定義

オーバーライドする属性のコレクションを表すオブジェクトを取得します。

オーバーロード

名前 説明
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 オブジェクトを作成します。 この例では、XmlAttributes オブジェクトのXmlRoot プロパティにXmlRootAttributeを割り当て、XmlAttributes オブジェクトをXmlAttributeOverrides オブジェクトに追加します。 最後に、シリアル化されたクラスのTypeXmlAttributeOverrides オブジェクトに渡すことによって、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

注釈

このオーバーロードを使用して、XmlRootAttributeまたはXmlTypeAttribute オブジェクトの属性を含むXmlAttributes オブジェクトを返します。

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

返す XmlAttributes を指定するオーバーライドされたメンバーの名前。

プロパティ値

オーバーライドする属性のコレクションを表す XmlAttributes

次の例では、 XmlAttributeOverrides オブジェクト、 XmlAttributes、および XmlAttributeAttribute オブジェクトを作成します。 この例では、XmlAttributes オブジェクトのXmlAttribute プロパティにXmlAttributeAttributeを割り当て、XmlAttributes オブジェクトをXmlAttributeOverrides オブジェクトに追加します。 最後に、この例では、シリアル化されたクラスとメンバー名のTypeXmlAttributeOverrides オブジェクトに渡すことによって、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

注釈

このオーバーロードを使用して、XmlArrayAttributeXmlArrayItemAttributeXmlAttributeAttributeXmlElementAttribute、またはXmlEnumAttributeをオーバーライドするオブジェクトを含むXmlAttributes オブジェクトを返します。 XmlAttributes オブジェクトにXmlRootAttributeまたはXmlTypeAttributeが含まれている場合は、オーバーライドされた型のみを指定するオーバーロードを使用する必要があります。

こちらもご覧ください

適用対象