Bagikan melalui


XmlIncludeAttribute(Type) Konstruktor

Definisi

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

type
Type

Objek Type yang akan disertakan.

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

Berlaku untuk