The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
XmlIncludeAttribute::Type Property
.NET Framework (current version)
Gets or sets the type of the object to include.
Assembly: System.Xml (in System.Xml.dll)
The following example defines a class named Group, which contains a field named Employees that returns an array of Employee objects. The example derives the Manager class from the Employee class, and applies the XmlIncludeAttribute to the Employee class. When the example creates a Group object, it inserts a Manager object into the Employee array. Lastly, the example serializes the Group object.
#using <System.Xml.dll> #using <System.dll> using namespace System; using namespace System::IO; using namespace System::Xml::Serialization; ref class Employee; ref class Manager; ref class Group { public: array<Employee^>^Employees; }; // Instruct the XmlSerializer to accept Manager types as well. [XmlInclude(Manager::typeid)] public ref class Employee { public: String^ Name; }; public ref class Manager: public Employee { public: int Level; }; void SerializeObject( String^ filename ) { XmlSerializer^ s = gcnew XmlSerializer( Group::typeid ); TextWriter^ writer = gcnew StreamWriter( filename ); Group^ group = gcnew Group; Manager^ manager = gcnew Manager; Employee^ emp1 = gcnew Employee; Employee^ emp2 = gcnew Employee; manager->Name = "Zeus"; manager->Level = 2; emp1->Name = "Ares"; emp2->Name = "Artemis"; array<Employee^>^emps = {manager,emp1,emp2}; group->Employees = emps; s->Serialize( writer, group ); writer->Close(); } void DeserializeObject( String^ filename ) { FileStream^ fs = gcnew FileStream( filename,FileMode::Open ); XmlSerializer^ x = gcnew XmlSerializer( Group::typeid ); Group^ g = dynamic_cast<Group^>(x->Deserialize( fs )); Console::Write( "Members:" ); System::Collections::IEnumerator^ myEnum = g->Employees->GetEnumerator(); while ( myEnum->MoveNext() ) { Employee^ e = safe_cast<Employee^>(myEnum->Current); Console::WriteLine( "\t{0}", e->Name ); } } int main() { SerializeObject( "IncludeExample.xml" ); DeserializeObject( "IncludeExample.xml" ); }
Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Show: