XmlIncludeAttribute(Type) 생성자

정의

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)

매개 변수

type
Type

포함할 개체의 Type입니다.

예제

다음 예제에서는 세 클래스를 보여 줍니다. 그 중 두 클래스는 세 번째 클래스에서 상속됩니다. 이 예제에서는 두 파생 클래스 중 하나의 인스턴스를 반환하는 메서드에 적용 XmlIncludeAttribute 합니다. 이 예제에서는 반환된 Type 개체의 형식으로 속성을 설정합니다.

public ref class Vehicle{};

public ref class Car: public Vehicle{};

public ref class Truck: public Vehicle{};

public ref class Sample
{
public:

   [WebMethodAttribute]
   [XmlInclude(Car::typeid)]
   [XmlInclude(Truck::typeid)]
   Vehicle^ ReturnVehicle( int i )
   {
      if ( i == 0 )
            return gcnew Car;
      else
            return gcnew Truck;
   }
};
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

적용 대상