UnreferencedObjectEventArgs Class
Provides data for the known, but unreferenced, object found in an encoded SOAP XML stream during deserialization.
Assembly: System.Xml (in System.Xml.dll)
The UnreferencedObjectEventArgs type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() | UnreferencedObjectEventArgs | Initializes a new instance of the UnreferencedObjectEventArgs class. |
| Name | Description | |
|---|---|---|
![]() ![]() | UnreferencedId | Gets the ID of the object. |
![]() ![]() | UnreferencedObject | Gets the deserialized, but unreferenced, object. |
| Name | Description | |
|---|---|---|
![]() ![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() ![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() ![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() ![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() ![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() ![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
For more information about the UnreferencedObjectEventArgs class, see the UnreferencedObject event of the XmlSerializer.
The UnreferencedObject event occurs only when you call the Deserialize method.
For more information about handling events, see Events Overview (Windows Forms)
The following example adds an UnreferencedObjectEventHandler to an XmlSerializer. The event is handled by the Serializer_UnreferencedObject method. To run the example, cut and paste the following XML into a file named UnrefObj.xml.
<wrapper>
<Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="id1" n1:GroupName=".NET" xmlns:n1="http://www.cpandl.com">
</Group>
<Vehicle id="id2" n1:type="Vehicle" xmlns:n1="http://www.w3.org/2001/XMLSchema-instance">
<licenseNumber xmlns:q1="http://www.w3.org/2001/XMLSchema" n1:type="q1:string">ABCD</licenseNumber>
</Vehicle>
<Vehicle id="id3" n1:type="Vehicle" xmlns:n1="http://www.w3.org/2001/XMLSchema-instance">
<licenseNumber xmlns:q1="http://www.w3.org/2001/XMLSchema" n1:type="q1:string">1234</licenseNumber>
</Vehicle>
</wrapper>
#using <System.Xml.dll> #using <System.dll> using namespace System; using namespace System::IO; using namespace System::Text; using namespace System::Xml; using namespace System::Xml::Serialization; using namespace System::Xml::Schema; ref class Vehicle; [SoapInclude(Vehicle::typeid)] public ref class Vehicle { public: String^ licenseNumber; }; // You must use the SoapIncludeAttribute to inform the XmlSerializer // that the Vehicle type should be recognized when deserializing. [SoapInclude(Vehicle::typeid)] public ref class Group { public: String^ GroupName; Vehicle^ GroupVehicle; }; public ref class Run { public: void DeserializeObject( String^ filename ) { // Create an instance of the XmlSerializer class. XmlTypeMapping^ myMapping = ((gcnew SoapReflectionImporter)->ImportTypeMapping( Group::typeid )); XmlSerializer^ mySerializer = gcnew XmlSerializer( myMapping ); mySerializer->UnreferencedObject += gcnew UnreferencedObjectEventHandler( this, &Run::Serializer_UnreferencedObject ); // Reading the file requires an XmlTextReader. XmlTextReader^ reader = gcnew XmlTextReader( filename ); reader->ReadStartElement(); // Deserialize and cast the object. Group^ myGroup; myGroup = dynamic_cast<Group^>(mySerializer->Deserialize( reader )); reader->ReadEndElement(); reader->Close(); } private: void Serializer_UnreferencedObject( Object^ /*sender*/, UnreferencedObjectEventArgs^ e ) { Console::WriteLine( "UnreferencedObject:" ); Console::WriteLine( "ID: {0}", e->UnreferencedId ); Console::WriteLine( "UnreferencedObject: {0}", e->UnreferencedObject ); Vehicle^ myVehicle = dynamic_cast<Vehicle^>(e->UnreferencedObject); Console::WriteLine( "License: {0}", myVehicle->licenseNumber ); } }; int main() { Run^ test = gcnew Run; test->DeserializeObject( "UnrefObj.xml" ); } // The file named S"UnrefObj.xml" should contain this XML: // <wrapper> // <Group xmlns:xsi=S"http://www.w3.org/2001/XMLSchema-instance" //xmlns:xsd=S"http://www.w3.org/2001/XMLSchema" id=S"id1" //n1:GroupName=S".NET" xmlns:n1=S"http://www.cpandl.com"> // </Group> //<Vehicle id=S"id2" n1:type=S"Vehicle" //xmlns:n1=S"http://www.w3.org/2001/XMLSchema-instance"> // <licenseNumber xmlns:q1=S"http://www.w3.org/2001/XMLSchema" //n1:type=S"q1:String*">ABCD</licenseNumber> // </Vehicle> //<Vehicle id=S"id3" n1:type=S"Vehicle" //xmlns:n1=S"http://www.w3.org/2001/XMLSchema-instance"> // <licenseNumber xmlns:q1=S"http://www.w3.org/2001/XMLSchema" //n1:type=S"q1:String*">1234</licenseNumber> // </Vehicle> //</wrapper>
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
