UnreferencedObjectEventArgs.UnreferencedId Propriedade


Obtém a ID do objeto.Gets the ID of the object.

 property System::String ^ UnreferencedId { System::String ^ get(); };
public string UnreferencedId { get; }
member this.UnreferencedId : string
Public ReadOnly Property UnreferencedId As String

Valor da propriedade

A ID do objeto.The ID of the object.


O exemplo a seguir adiciona UnreferencedObjectEventHandler um a XmlSerializerum.The following example adds an UnreferencedObjectEventHandler to an XmlSerializer. O evento é manipulado pelo Serializer_UnreferencedObject método.The event is handled by the Serializer_UnreferencedObject method. Para executar o exemplo, recorte e cole o XML a seguir em um arquivo chamado UnrefObj. xml.To run the example, cut and paste the following XML into a file named UnrefObj.xml.

  <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">  
<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 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>  
#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;

public ref class Vehicle
   String^ licenseNumber;

// You must use the SoapIncludeAttribute to inform the XmlSerializer
// that the Vehicle type should be recognized when deserializing.

public ref class Group
   String^ GroupName;
   Vehicle^ GroupVehicle;

public ref class Run
   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 );
      // Deserialize and cast the object.
      Group^ myGroup;
      myGroup = dynamic_cast<Group^>(mySerializer->Deserialize( reader ));

   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:
//  <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">
//<Vehicle id=S"id2" n1:type=S"Vehicle" 
//   <licenseNumber xmlns:q1=S"http://www.w3.org/2001/XMLSchema" 
//<Vehicle id=S"id3" n1:type=S"Vehicle" 
//    <licenseNumber xmlns:q1=S"http://www.w3.org/2001/XMLSchema" 
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;

// You must use the SoapIncludeAttribute to inform the XmlSerializer
// that the Vehicle type should be recognized when deserializing.
public class Group
   public string GroupName;
   public Vehicle GroupVehicle;
public class Vehicle
   public string licenseNumber;

public class Run
   public static void Main()
      Run test = new Run();
   public void DeserializeObject(string filename)
      // Create an instance of the XmlSerializer class.
      XmlTypeMapping myMapping = 
      (new SoapReflectionImporter().ImportTypeMapping(
      XmlSerializer mySerializer =  
      new XmlSerializer(myMapping);
      mySerializer.UnreferencedObject += 
      new UnreferencedObjectEventHandler

      // Reading the file requires an  XmlTextReader.
      XmlTextReader reader= 
      new XmlTextReader(filename);

      // Deserialize and cast the object.
      Group myGroup; 
      myGroup = (Group) mySerializer.Deserialize(reader);

   private void Serializer_UnreferencedObject
   (object sender, UnreferencedObjectEventArgs e){
      Console.WriteLine("ID: " + e.UnreferencedId);
      Console.WriteLine("UnreferencedObject: " + e.UnreferencedObject);
      Vehicle myVehicle = (Vehicle) e.UnreferencedObject;
      Console.WriteLine("License: " + myVehicle.licenseNumber);

// The file named "UnrefObj.xml" should contain this XML:

//  <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">

//<Vehicle id="id2" n1:type="Vehicle" 
//   <licenseNumber xmlns:q1="http://www.w3.org/2001/XMLSchema" 

//<Vehicle id="id3" n1:type="Vehicle" 
//    <licenseNumber xmlns:q1="http://www.w3.org/2001/XMLSchema" 

Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Xml.Schema

' You must use the SoapIncludeAttribute to inform the XmlSerializer
' that the Vehicle type should be recognized when deserializing.
<SoapInclude(GetType(Vehicle))> _
Public Class Group
    Public GroupName As String 
   public GroupVehicle As Vehicle 
End Class

Public Class Vehicle
   Public licenseNumber As String 
End Class

Public Class Run
   Shared Sub Main()
      Dim test As Run = new Run()
   End Sub
   Public Sub DeserializeObject(filename As String)
      ' Create an instance of the XmlSerializer class.
      Dim myMapping As XmlTypeMapping = _
      (new SoapReflectionImporter().ImportTypeMapping _
      Dim mySerializer As XmlSerializer =  _
      new XmlSerializer(myMapping)

      AddHandler mySerializer.UnreferencedObject, _
      AddressOf Serializer_UnreferencedObject

      ' Reading the file requires an  XmlTextReader.
      Dim reader As XmlTextReader = _
      new XmlTextReader(filename)

      ' Deserialize and cast the object.
      Dim myGroup As Group  
      myGroup = CType( mySerializer.Deserialize(reader), Group)
   End Sub
   Private Sub Serializer_UnreferencedObject _
   (sender As object , e As UnreferencedObjectEventArgs)
      Console.WriteLine("ID: " + e.UnreferencedId)
      Console.WriteLine("UnreferencedObject: " + e.UnreferencedObject)
      Dim myVehicle As Vehicle = CType(e.UnreferencedObject, Vehicle)
      Console.WriteLine("License: " + myVehicle.licenseNumber)
       End Sub
 End Class
' The XML document should contain this information:

'  <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">

'<Vehicle id="id2" n1:type="Vehicle" 
'    <licenseNumber xmlns:q1="http:'www.w3.org/2001/XMLSchema" 

'<Vehicle id="id3" n1:type="Vehicle" 
'    <licenseNumber xmlns:q1="http:'www.w3.org/2001/XMLSchema" 


Use a UnreferencedId Propriedade quando você precisar saber quando mais de um objeto gerar o evento.Use the UnreferencedId property when you need to know when more than one object raises the event. A propriedade permite que você Diferencie entre várias instâncias de objetos não referenciados.The property allows you to distinguish between multiple instances of unreferenced objects.

Para obter mais informações sobre UnreferencedId a propriedade, consulte UnreferencedObject o evento.For more information about the UnreferencedId property, see the UnreferencedObject event.

Aplica-se a