次の方法で共有


XmlIncludeAttribute コンストラクタ

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

Public Sub New( _
   ByVal type As Type _)
[C#]
public XmlIncludeAttribute(
   Typetype);
[C++]
public: XmlIncludeAttribute(
   Type* type);
[JScript]
public function XmlIncludeAttribute(
   type : Type);

パラメータ

  • type
    含めるオブジェクトの Type

使用例

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

 
Public Class Vehicle
End Class
 
Public Class Car
    Inherits Vehicle
End Class
 
Public Class Truck
    Inherits Vehicle
End Class
 
Public Class Sample    
    <WebMethod(), _
     XmlInclude(GetType(Car)), _
     XmlInclude(GetType(Truck))> _
    Public Function ReturnVehicle(i As Integer) As Vehicle
        
        If i = 0 Then
            Return New Car()
        Else
            Return New Truck()
        End If
    End Function
End Class

[C#] 
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();
   }
}   

[C++] 
public __gc class Vehicle{};
 
public __gc class Car: public Vehicle{};
 
public __gc class Truck: public Vehicle{};
 
public __gc class Sample
{
public:
[WebMethodAttribute]
[XmlInclude(__typeof(Car))]
[XmlInclude(__typeof(Truck))]
Vehicle* ReturnVehicle(int i){
   if(i == 0)
      return new Car();
   else
      return new Truck();
   }
};   

[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 ファミリ, .NET Compact Framework - Windows CE .NET

参照

XmlIncludeAttribute クラス | XmlIncludeAttribute メンバ | System.Xml.Serialization 名前空間