XmlIncludeAttribute(Type) Constructor
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the XmlIncludeAttribute class.
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)
Parameters
Examples
The following example shows three classes, two of which inherit from the third. The example applies the XmlIncludeAttribute to a method that returns an instance of one of the two derived classes. The example sets the Type property to the type of the returned object.
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
Applies to
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET