Export (0) Print
Expand All

XmlIncludeAttribute Constructor

Initializes a new instance of the XmlIncludeAttribute class.

[Visual Basic]
Public Sub New( _
   ByVal type As Type _
)
[C#]
public XmlIncludeAttribute(
   Type type
);
[C++]
public: XmlIncludeAttribute(
   Type* type
);
[JScript]
public function XmlIncludeAttribute(
   type : Type
);

Parameters

type
The Type of the object to include.

Example

[Visual Basic, C#, C++] The following example show 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.

[Visual Basic] 
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

[C#] 
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();
   }
}   

[C++] 
public __gc class Vehicle{};
 
public __gc class Car: public Vehicle{};
 
public __gc class Truck: public Vehicle{};
 
public __gc class Sample
{
public:
[WebMethodAttribute]
[XmlInclude(__typeof(Car))]
[XmlInclude(__typeof(Truck))]
Vehicle* ReturnVehicle(int i){
   if(i == 0)
      return new Car();
   else
      return new Truck();
   }
};   

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

XmlIncludeAttribute Class | XmlIncludeAttribute Members | System.Xml.Serialization Namespace

Show:
© 2015 Microsoft