Sdílet prostřednictvím


XmlIncludeAttribute(Type) Konstruktor

Definice

Inicializuje novou instanci XmlIncludeAttribute třídy.

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)

Parametry

type
Type

Objekt Type , který se má zahrnout.

Příklady

Následující příklad ukazuje tři třídy, z nichž dvě dědí z třetí třídy. Příklad aplikuje na XmlIncludeAttribute metodu, která vrací instanci jedné ze dvou odvozených tříd. Příklad nastaví Type vlastnost na typ vráceného objektu.

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

Platí pro