Condividi tramite


XmlIncludeAttribute(Type) Costruttore

Definizione

Inizializza una nuova istanza della classe 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)

Parametri

type
Type

Oggetto Type dell'oggetto da includere.

Esempio

L'esempio seguente mostra tre classi, due delle quali ereditano dal terzo. Nell'esempio viene applicato a XmlIncludeAttribute un metodo che restituisce un'istanza di una delle due classi derivate. Nell'esempio la Type proprietà viene impostata sul tipo dell'oggetto restituito.

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

Si applica a