XmlElementAttributes.Add メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlElementAttributes.Add メソッドの意味・解説 

XmlElementAttributes.Add メソッド

XmlElementAttributeコレクション追加します

名前空間: System.Xml.Serialization
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Public Function Add ( _
    attribute As XmlElementAttribute _
) As Integer
Dim instance As XmlElementAttributes
Dim attribute As XmlElementAttribute
Dim returnValue As Integer

returnValue = instance.Add(attribute)
public int Add (
    XmlElementAttribute attribute
)
public:
int Add (
    XmlElementAttribute^ attribute
)
public int Add (
    XmlElementAttribute attribute
)
public function Add (
    attribute : XmlElementAttribute
) : int

パラメータ

attribute

追加する XmlElementAttribute。

戻り値
新しく追加された項目の 0 から始まるインデックス

使用例使用例

2 つXmlElementAttribute オブジェクト作成しAdd メソッド呼び出して、これらのオブジェクトを XmlElementAttributes に追加する例を次に示します。この例では、次に XmlElementAttributes を XmlAttributeOverrides に追加し、これを使用してTransportation クラスインスタンスシリアル化できる XmlSerializer を作成してます。

    Public Function CreateOverrider() As
 XmlSerializer
        ' Create XmlAttributes and XmlAttributeOverrides instances.
        Dim attrs As New
 XmlAttributes()
        Dim xOver As New
 XmlAttributeOverrides()
        
        ' Create an XmlElementAttributes to override
        ' the Vehicles property. 
        Dim xElement1 As New
 XmlElementAttribute(GetType(Truck))
        ' Add the XmlElementAttribute to the collection.
        attrs.XmlElements.Add(xElement1)
        
        ' Create a second XmlElementAttribute, and
        ' add to the collection. 
        Dim xElement2 As New
 XmlElementAttribute(GetType(Train))
        attrs.XmlElements.Add(xElement2)
        
        ' Add the XmlAttributes to the XmlAttributeOverrides,
        ' specifying the member to override. 
        xOver.Add(GetType(Transportation), "Vehicles",
 attrs)
        
        ' Create the XmlSerializer, and return it.
        Dim xSer As New
 XmlSerializer(GetType(Transportation), xOver)
        Return xSer
    End Function
End Class
 
public XmlSerializer CreateOverrider()
{
   // Create XmlAttributes and XmlAttributeOverrides instances.
   
   XmlAttributes attrs = new XmlAttributes();
   XmlAttributeOverrides xOver = 
   new XmlAttributeOverrides();
      
   /* Create an XmlElementAttributes to override 
      the Vehicles property. */
   XmlElementAttribute xElement1 = 
   new XmlElementAttribute(typeof(Truck));
   // Add the XmlElementAttribute to the collection.
   attrs.XmlElements.Add(xElement1);

   /* Create a second XmlElementAttribute, and 
      add to the collection. */
   XmlElementAttribute xElement2 = 
   new XmlElementAttribute(typeof(Train));
   attrs.XmlElements.Add(xElement2);

   /* Add the XmlAttributes to the XmlAttributeOverrides,
      specifying the member to override. */
   xOver.Add(typeof(Transportation), "Vehicles", attrs);
      
   // Create the XmlSerializer, and return it.
   XmlSerializer xSer = new XmlSerializer
   (typeof(Transportation), xOver);
   return xSer;
}

public:
   XmlSerializer^ CreateOverrider()
   {
      // Create XmlAttributes and XmlAttributeOverrides instances.

      XmlAttributes^ attrs = gcnew XmlAttributes;
      XmlAttributeOverrides^ xOver =
         gcnew XmlAttributeOverrides;

      /* Create an XmlElementAttributes to override 
            the Vehicles property. */
      XmlElementAttribute^ xElement1 =
         gcnew XmlElementAttribute( Truck::typeid );
      // Add the XmlElementAttribute to the collection.
      attrs->XmlElements->Add( xElement1 );

      /* Create a second XmlElementAttribute, and 
            add to the collection. */
      XmlElementAttribute^ xElement2 =
         gcnew XmlElementAttribute( Train::typeid );
      attrs->XmlElements->Add( xElement2 );

      /* Add the XmlAttributes to the XmlAttributeOverrides,
            specifying the member to override. */
      xOver->Add( Transportation::typeid, "Vehicles", attrs );

      // Create the XmlSerializer, and return it.
      XmlSerializer^ xSer = gcnew XmlSerializer(
         Transportation::typeid,xOver );
      return xSer;
   }
public XmlSerializer CreateOverrider()
{
    // Create XmlAttributes and XmlAttributeOverrides instances.
    XmlAttributes attrs = new XmlAttributes();
    XmlAttributeOverrides xOver = new XmlAttributeOverrides();

    /* Create an XmlElementAttributes to override 
       the Vehicles property. */
    XmlElementAttribute xElement1 =
        new XmlElementAttribute(Truck.class.ToType());

    // Add the XmlElementAttribute to the collection.
    attrs.get_XmlElements().Add(xElement1);

    /* Create a second XmlElementAttribute, and 
       add to the collection. */
    XmlElementAttribute xElement2 =
        new XmlElementAttribute(Train.class.ToType());
    attrs.get_XmlElements().Add(xElement2);

    /* Add the XmlAttributes to the XmlAttributeOverrides,
       specifying the member to override. */
    xOver.Add(Transportation.class.ToType(), "Vehicles",
 attrs);

    // Create the XmlSerializer, and return it.
    XmlSerializer xSer =
        new XmlSerializer(Transportation.class.ToType(),
 xOver);
    return xSer;
} //CreateOverrider
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlElementAttributes クラス
XmlElementAttributes メンバ
System.Xml.Serialization 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

XmlElementAttributes.Add メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XmlElementAttributes.Add メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS