Export (0) Print
Expand All

XmlIncludeAttribute Constructor

Initializes a new instance of the XmlIncludeAttribute class.

Namespace:  System.Xml.Serialization
Assembly:  System.Xml (in System.Xml.dll)

public XmlIncludeAttribute(
	Type type
)

Parameters

type
Type: System.Type

The Type of the object to include.

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 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 __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();
   }
};   

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft