.NET Framework Class Library
XmlIncludeAttribute Class

Allows the XmlSerializer to recognize a type when it serializes or deserializes an object.

Inheritance Hierarchy
SystemObject
   SystemAttribute
    System.Xml.SerializationXmlIncludeAttribute

Namespace:   System.Xml.Serialization
Assembly:  System.Xml (in System.Xml.dll)
Syntax
<[%$TOPIC/k4b581sd_en-us_VS_110_3_0_0_0_0%]([%$TOPIC/k4b581sd_en-us_VS_110_3_0_0_0_1%].Class Or [%$TOPIC/k4b581sd_en-us_VS_110_3_0_0_0_2%].Struct Or [%$TOPIC/k4b581sd_en-us_VS_110_3_0_0_0_3%].Method Or [%$TOPIC/k4b581sd_en-us_VS_110_3_0_0_0_4%].Interface, AllowMultiple := True)> _
Public Class XmlIncludeAttribute _
	Inherits [%$TOPIC/k4b581sd_en-us_VS_110_3_0_0_0_5%]
[[%$TOPIC/k4b581sd_en-us_VS_110_3_0_1_0_0%]([%$TOPIC/k4b581sd_en-us_VS_110_3_0_1_0_1%].Class|[%$TOPIC/k4b581sd_en-us_VS_110_3_0_1_0_2%].Struct|[%$TOPIC/k4b581sd_en-us_VS_110_3_0_1_0_3%].Method|[%$TOPIC/k4b581sd_en-us_VS_110_3_0_1_0_4%].Interface, AllowMultiple = true)]
public class XmlIncludeAttribute : [%$TOPIC/k4b581sd_en-us_VS_110_3_0_1_0_5%]
[[%$TOPIC/k4b581sd_en-us_VS_110_3_0_2_0_0%]([%$TOPIC/k4b581sd_en-us_VS_110_3_0_2_0_1%]::Class|[%$TOPIC/k4b581sd_en-us_VS_110_3_0_2_0_2%]::Struct|[%$TOPIC/k4b581sd_en-us_VS_110_3_0_2_0_3%]::Method|[%$TOPIC/k4b581sd_en-us_VS_110_3_0_2_0_4%]::Interface, AllowMultiple = true)]
public ref class XmlIncludeAttribute : public [%$TOPIC/k4b581sd_en-us_VS_110_3_0_2_0_5%]
[<[%$TOPIC/k4b581sd_en-us_VS_110_3_0_3_0_0%]([%$TOPIC/k4b581sd_en-us_VS_110_3_0_3_0_1%].Class|[%$TOPIC/k4b581sd_en-us_VS_110_3_0_3_0_2%].Struct|[%$TOPIC/k4b581sd_en-us_VS_110_3_0_3_0_3%].Method|[%$TOPIC/k4b581sd_en-us_VS_110_3_0_3_0_4%].Interface, AllowMultiple = true)>]
type XmlIncludeAttribute =  
    class 
        inherit [%$TOPIC/k4b581sd_en-us_VS_110_3_0_3_0_5%] 
    end
public class XmlIncludeAttribute extends [%$TOPIC/k4b581sd_en-us_VS_110_3_0_4_0_0%]

The XmlIncludeAttribute type exposes the following members.

Constructors
  NameDescription
Public method Supported by the XNA Framework Supported by Portable Class Library XmlIncludeAttributeInitializes a new instance of the XmlIncludeAttribute class.
Top
Properties
  NameDescription
Public property Supported by the XNA Framework Supported by Portable Class Library TypeGets or sets the type of the object to include.
Public property TypeIdWhen implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)
Top
Methods
  NameDescription
Public method Supported by the XNA Framework Supported by Portable Class Library EqualsInfrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Protected method Supported by the XNA Framework Supported by Portable Class Library FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Supported by the XNA Framework Supported by Portable Class Library GetHashCodeReturns the hash code for this instance. (Inherited from Attribute.)
Public method Supported by the XNA Framework Supported by Portable Class Library GetTypeGets the Type of the current instance. (Inherited from Object.)
Public method IsDefaultAttributeWhen overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)
Public method Supported by the XNA Framework MatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Protected method Supported by the XNA Framework Supported by Portable Class Library MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public method Supported by the XNA Framework Supported by Portable Class Library ToStringReturns a string that represents the current object. (Inherited from Object.)
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implemetation Private method _AttributeGetIDsOfNamesMaps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeGetTypeInfoRetrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeGetTypeInfoCountRetrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeInvokeProvides access to properties and methods exposed by an object. (Inherited from Attribute.)
Top
Remarks

Use the XmlIncludeAttribute when you call the Serialize or Deserialize method of the XmlSerializer class.

When applying the XmlIncludeAttribute, specify the Type of the derived class. When the XmlSerializer serializes objects that include both the base and the derived class, it can then recognize both object types.

You can use the XmlIncludeAttribute to include derived classes in service description documents that are written in the Web Services Description Language (WSDL). For example, if a method returns an Object, apply the XmlIncludeAttribute to the method and specify the actual types to return.

For more information on the WSDL, see "Web Services Description Language (WSDL) 1.1" at www.w3.org.

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 derived classes.

<%@ WebService Language="C#" Class="Test" %>

using System;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Services.Description;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Data;

public class Test : WebService {
   [WebMethod()]
   [return:XmlElement("MyTime", DataType="time")]
   public DateTime EchoString([XmlElement(DataType="string")] 
   string strval) {
        return DateTime.Now;
   }

   [WebMethod()]
   [XmlInclude(typeof(Car)), XmlInclude(typeof(Bike))]
   public Vehicle Vehicle(string licenseNumber) {
      if (licenseNumber == "0") {
         Vehicle v = new Car();
         v.licenseNumber = licenseNumber;
         return v;
      }
      else if (licenseNumber == "1") {
          Vehicle v = new Bike();
          v.licenseNumber = licenseNumber;
          return v;
      }
      else {
         return null;
      }
   }
}
[XmlRoot("NewVehicle")] 
public abstract class Vehicle {
    public string licenseNumber;
    public DateTime make;
}

public class Car : Vehicle {
}

public class Bike : Vehicle {
}
   
Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.