XmlIncludeAttribute(Type) Konstruktor
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menginisialisasi instans baru dari kelas 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)
Parameter
Contoh
Contoh berikut menunjukkan tiga kelas, dua di antaranya mewarisi dari kelas ketiga. Contoh menerapkan ke XmlIncludeAttribute metode yang mengembalikan instans dari salah satu dari dua kelas turunan. Contoh mengatur Type properti ke jenis objek yang dikembalikan.
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