次の方法で共有


XmlIncludeAttribute(Type) コンストラクター

定義

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

public:
 XmlIncludeAttribute(Type ^ type);
public XmlIncludeAttribute(Type type);
public XmlIncludeAttribute(Type? type);
new System.Xml.Serialization.XmlIncludeAttribute : Type -> System.Xml.Serialization.XmlIncludeAttribute
Public Sub New (type As 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 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

適用対象