XmlIncludeAttributeとは? わかりやすく解説

XmlIncludeAttribute クラス

XmlSerializer がオブジェクトをシリアル化または逆シリアル化するときに、型を認識できるようにします。

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

<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Struct
 Or AttributeTargets.Method Or AttributeTargets.Interface,
 AllowMultiple:=True)> _
Public Class XmlIncludeAttribute
    Inherits Attribute
Dim instance As XmlIncludeAttribute
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Method|AttributeTargets.Interface,
 AllowMultiple=true)] 
public class XmlIncludeAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Method|AttributeTargets::Interface,
 AllowMultiple=true)] 
public ref class XmlIncludeAttribute : public
 Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Method|AttributeTargets.Interface,
 AllowMultiple=true) */ 
public class XmlIncludeAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Method|AttributeTargets.Interface,
 AllowMultiple=true) 
public class XmlIncludeAttribute extends
 Attribute
解説解説
使用例使用例

次の例では 3 つのクラスがあり、そのうち 2 つは 3 番目のクラスから継承したクラスです。この例では、1 つの派生クラスのインスタンスを返すメソッドに XmlIncludeAttribute を適用します。

<%@ WebService Language="C#" Class="Test" %>
 
using System;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Services.Description;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Data;
 
public class Test : WebService {
   [WebMethod()]
   [return:XmlElement("MyTime", DataType="time")]
   public DateTime EchoString([XmlElement(DataType="string")]
 
   string strval) {
        return DateTime.Now;
   }
 
   [WebMethod()]
   [XmlInclude(typeof(Car)), XmlInclude(typeof(Bike))]
   public Vehicle Vehicle(string licenseNumber)
 {
      if (licenseNumber == "0") {
         Vehicle v = new Car();
         v.licenseNumber = licenseNumber;
         return v;
      }
      else if (licenseNumber == "1")
 {
          Vehicle v = new Bike();
          v.licenseNumber = licenseNumber;
          return v;
      }
      else {
         return null;
      }
   }
}
[XmlRoot("NewVehicle")] 
public abstract class Vehicle {
    public string licenseNumber;
    public DateTime make;
}
 
public class Car : Vehicle {
}
 
public class Bike : Vehicle {
}
   
継承階層継承階層
System.Object
   System.Attribute
    System.Xml.Serialization.XmlIncludeAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

XmlIncludeAttribute コンストラクタ

XmlIncludeAttribute クラスの新しいインスタンスを初期化します。

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

Dim type As Type

Dim instance As New XmlIncludeAttribute(type)
public XmlIncludeAttribute (
    Type type
)
public:
XmlIncludeAttribute (
    Type^ type
)
public XmlIncludeAttribute (
    Type type
)
public function XmlIncludeAttribute (
    type : Type
)

パラメータ

type

含めるオブジェクトの Type。

使用例使用例

次の例では 3 つのクラスがあり、そのうち 2 つは 3 番目のクラスから継承したクラスです。この例では、2 つのうちの 1 つの派生クラスのインスタンスを返すメソッドに XmlIncludeAttribute を適用します。Type プロパティには、返されるオブジェクトの型が設定されます。

public class Vehicle{}
 
public class Car:Vehicle{}
 
public class Truck:Vehicle{}
 
public class Sample
{
[WebMethodAttribute]
[XmlInclude(typeof(Car))]
[XmlInclude(typeof(Truck))]
public Vehicle ReturnVehicle(int i){
   if(i == 0)
      return new Car();
   else
      return new Truck();
   }
}   
public ref class Vehicle{};

public ref class Car: public
 Vehicle{};

public ref class Truck: public
 Vehicle{};

public ref class Sample
{
public:

   [WebMethodAttribute]
   [XmlInclude(Car::typeid)]
   [XmlInclude(Truck::typeid)]
   Vehicle^ ReturnVehicle( int i )
   {
      if ( i == 0 )
            return gcnew Car;
      else
            return gcnew Truck;
   }
};
public class Vehicle
{
} //Vehicle

public class Car extends Vehicle
{
} //Car

public class Truck extends Vehicle
{
} //Truck

public class Sample
{
    /** @attribute WebMethodAttribute()
     */
    /** @attribute XmlInclude(Car.class)
     */
    /** @attribute XmlInclude(Truck.class)
     */
    public Vehicle ReturnVehicle(int i)
    {
        if (i == 0) {
            return new Car();
        }
        else {
            return new Truck();
        }
    } //ReturnVehicle
} //Sample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlIncludeAttribute クラス
XmlIncludeAttribute メンバ
System.Xml.Serialization 名前空間

XmlIncludeAttribute プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ .NET Compact Framework によるサポート TypeId  派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。 ( Attribute から継承されます。)
参照参照

関連項目

XmlIncludeAttribute クラス
System.Xml.Serialization 名前空間
XmlSerializer
XmlAttributes クラス

その他の技術情報

XML シリアル化の概要
方法 : XML ストリームの代替要素名を指定する
属性を使用した XML シリアル化の制御
XML シリアル化の例
XML スキーマ定義ツール (Xsd.exe)

XmlIncludeAttribute メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスのハッシュ コードを返します。 ( Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 ( Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 ( Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 ( Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

XmlIncludeAttribute クラス
System.Xml.Serialization 名前空間
XmlSerializer
XmlAttributes クラス

その他の技術情報

XML シリアル化の概要
方法 : XML ストリームの代替要素名を指定する
属性を使用した XML シリアル化の制御
XML シリアル化の例
XML スキーマ定義ツール (Xsd.exe)

XmlIncludeAttribute メンバ

XmlSerializer がオブジェクトをシリアル化または逆シリアル化するときに、型を認識できるようにします。

XmlIncludeAttribute データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド XmlIncludeAttribute XmlIncludeAttribute クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ .NET Compact Framework によるサポート TypeId  派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。(Attribute から継承されます。)
パブリック メソッドパブリック メソッド
( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 (Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 (Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスのハッシュ コードを返します。 (Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 (Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 (Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

XmlIncludeAttribute クラス
System.Xml.Serialization 名前空間
XmlSerializer
XmlAttributes クラス

その他の技術情報

XML シリアル化の概要
方法 : XML ストリームの代替要素名を指定する
属性を使用した XML シリアル化の制御
XML シリアル化の例
XML スキーマ定義ツール (Xsd.exe)



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「XmlIncludeAttribute」の関連用語

XmlIncludeAttributeのお隣キーワード
検索ランキング

   

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



XmlIncludeAttributeのページの著作権

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

©2026 GRAS Group, Inc.RSS