XmlIncludeAttribute(Type) 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 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)
參數
範例
下列範例顯示三個類別,其中兩個類別繼承自第三個類別。 此範例會將 XmlIncludeAttribute 套用至傳回兩個衍生類別其中一個實例的方法。 此範例會將 Type 屬性設定為傳回物件的型別。
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{}
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