Udostępnij za pośrednictwem


XmlIncludeAttribute(Type) Konstruktor

Definicja

Inicjuje nowe wystąpienie klasy 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)

Parametry

type
Type

Obiekt Type do uwzględnienia.

Przykłady

W poniższym przykładzie przedstawiono trzy klasy, z których dwie dziedziczą po trzeciej. W przykładzie XmlIncludeAttribute zastosowano metodę zwracającą wystąpienie jednej z dwóch klas pochodnych. W przykładzie Type właściwość jest ustawiana na typ zwróconego obiektu.

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

Dotyczy