Partilhar via


XmlIncludeAttribute(Type) Construtor

Definição

Inicializa uma nova instância da 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)

Parâmetros

type
Type

O Type objeto a ser incluído.

Exemplos

O exemplo a seguir mostra três classes, duas das quais herdam da terceira. O exemplo aplica-se a XmlIncludeAttribute um método que retorna uma instância de uma das duas classes derivadas. O exemplo define a Type propriedade como o tipo do objeto retornado.

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

Aplica-se a