ObjectManager 클래스

정의

주의

Formatter-based serialization is obsolete and should not be used.

개체가 역직렬화될 때 추적합니다.

public ref class ObjectManager
public class ObjectManager
[System.Obsolete("Formatter-based serialization is obsolete and should not be used.", DiagnosticId="SYSLIB0050", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public class ObjectManager
[System.Runtime.InteropServices.ComVisible(true)]
public class ObjectManager
type ObjectManager = class
[<System.Obsolete("Formatter-based serialization is obsolete and should not be used.", DiagnosticId="SYSLIB0050", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
type ObjectManager = class
[<System.Runtime.InteropServices.ComVisible(true)>]
type ObjectManager = class
Public Class ObjectManager
상속
ObjectManager
특성

예제

다음 코드 예제를 사용 ObjectManager 하는 방법에 설명 합니다 클래스를 한 번만 각 개체를 트래버스 하는 개체 그래프를 통해 단계입니다.

using System;
using System.Text;
using System.Collections;
using System.Runtime.Serialization;
using System.Reflection;

// This class walks through all the objects once in an object graph.
public sealed class ObjectWalker : IEnumerable, IEnumerator {
   private Object m_current;

   // This stack contains the set of objects that will be enumerated.
   private Stack m_toWalk = new Stack();

   // The ObjectIDGenerator ensures that each object is enumerated just once.
   private ObjectIDGenerator m_idGen = new ObjectIDGenerator();

   // Construct an ObjectWalker passing the root of the object graph.
   public ObjectWalker(Object root) {
      Schedule(root);
   }

   // Return an enumerator so this class can be used with foreach.
   public IEnumerator GetEnumerator() {
      return this;
   }

   // Resetting the enumerator is not supported.
   public void Reset() {
      throw new NotSupportedException("Resetting the enumerator is not supported.");
   }

   // Return the enumeration's current object.
   public Object Current { get { return m_current; } }

   // Walk the reference of the passed-in object.
   private void Schedule(Object toSchedule) {
      if (toSchedule == null) return;

      // Ask the ObjectIDManager if this object has been examined before.
      Boolean firstOccurrence;
      m_idGen.GetId(toSchedule, out firstOccurrence);

      // If this object has been examined before, do not look at it again just return.
      if (!firstOccurrence) return;

      if (toSchedule.GetType().IsArray) {
         // The object is an array, schedule each element of the array to be looked at.
         foreach (Object item in ((Array)toSchedule)) Schedule(item);
      } else {
         // The object is not an array, schedule this object to be looked at.
         m_toWalk.Push(toSchedule);
      }
   }

   // Advance to the next item in the enumeration.
   public Boolean MoveNext() {
      // If there are no more items to enumerate, return false.
      if (m_toWalk.Count == 0) return false;

      // Check if the object is a terminal object (has no fields that refer to other objects).
      if (!IsTerminalObject(m_current = m_toWalk.Pop())) {
         // The object does have field, schedule the object's instance fields to be enumerated.
         foreach (FieldInfo fi in m_current.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) {
            Schedule(fi.GetValue(m_current));
         }
      }
      return true;
   }

   // Returns true if the object has no data fields with information of interest.
   private Boolean IsTerminalObject(Object data) {
      Type t = data.GetType();
      return t.IsPrimitive || t.IsEnum || t.IsPointer || data is String;
   }
}

public sealed class App {
   // Define some fields in the class to test the ObjectWalker.
   public String name = "Fred";
   public Int32 Age = 40;

   static void Main() {
      // Build an object graph using an array that refers to various objects.
      Object[] data = new Object[] { "Jeff", 123, 555L, (Byte) 35, new App() };

      // Construct an ObjectWalker and pass it the root of the object graph.
      ObjectWalker ow = new ObjectWalker(data);

      // Enumerate all of the objects in the graph and count the number of objects.
      Int64 num = 0;
      foreach (Object o in ow) {
         // Display each object's type and value as a string.
         Console.WriteLine("Object #{0}: Type={1}, Value's string={2}",
            num++, o.GetType(), o.ToString());
      }
   }
}

// This code produces the following output.
//
// Object #0: Type=App, Value's string=App
// Object #1: Type=System.Int32, Value's string=40
// Object #2: Type=System.String, Value's string=Fred
// Object #3: Type=System.Byte, Value's string=35
// Object #4: Type=System.Int64, Value's string=555
// Object #5: Type=System.Int32, Value's string=123
// Object #6: Type=System.String, Value's string=Jeff

설명

역직렬화하는 Formatter 동안 는 를 쿼리 ObjectManager 하여 직렬화된 스트림의 개체에 대한 참조가 이미 역직렬화된 개체(역방향 참조)를 참조하는지 또는 아직 역직렬화되지 않은 개체(정방향 참조)를 참조하는지 여부를 확인합니다. 직렬화된 스트림의 참조가 정방향 참조인 경우 는 Formatter 에 픽스업을 등록할 ObjectManager수 있습니다. 직렬화된 스트림의 참조가 역방향 참조인 경우 는 Formatter 즉시 참조를 완료합니다. Fixup은 개체 역직렬화 프로세스 중에 아직 완료되지 않은 개체 참조를 마무리하는 프로세스를 나타냅니다. 필수 개체가 역직렬화되면 는 ObjectManager 참조를 완료합니다.

ObjectManager 수정 순서를 지시하는 규칙 집합을 따릅니다. 를 구현 ISerializable 하거나 포함하는 모든 개체에는 ISerializationSurrogate 개체 트리가 역직렬화될 SerializationInfo 때 사용할 수 있는 모든 개체가 있을 것으로 예상할 수 있습니다. 그러나 부모 개체는 완전히 역직렬화될 때 모든 자식 개체가 완전히 완료될 것이라고 가정할 수 없습니다. 모든 자식 개체가 있지만 모든 손자 개체가 반드시 있는 것은 아닙니다. 개체가 자식 개체에서 코드를 실행하는 데 의존하는 특정 작업을 수행해야 하는 경우 이러한 작업을 지연시키고, 인터페이스를 IDeserializationCallback 구현하고, 이 인터페이스에서 다시 호출되는 경우에만 코드를 실행할 수 있습니다.

생성자

ObjectManager(ISurrogateSelector, StreamingContext)
사용되지 않음.

ObjectManager 클래스의 새 인스턴스를 초기화합니다.

메서드

DoFixups()
사용되지 않음.

기록된 픽스업을 모두 수행합니다.

Equals(Object)
사용되지 않음.

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()
사용되지 않음.

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetObject(Int64)
사용되지 않음.

지정된 개체 ID를 가진 개체를 반환합니다.

GetType()
사용되지 않음.

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()
사용되지 않음.

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
RaiseDeserializationEvent()
사용되지 않음.

IDeserializationCallback을 구현하는 등록된 개체에 대해 deserialization 이벤트를 발생시킵니다.

RaiseOnDeserializingEvent(Object)
사용되지 않음.

OnDeserializingAttribute로 표시된 메서드를 호출합니다.

RecordArrayElementFixup(Int64, Int32, Int64)
사용되지 않음.

배열에 있는 한 요소에 대한 픽스업을 기록합니다.

RecordArrayElementFixup(Int64, Int32[], Int64)
사용되지 않음.

배열에 있는 지정된 요소가 나중에 실행되도록 픽스업을 기록합니다.

RecordDelayedFixup(Int64, String, Int64)
사용되지 않음.

개체 멤버가 나중에 실행되도록 픽스업을 기록합니다.

RecordFixup(Int64, MemberInfo, Int64)
사용되지 않음.

개체 멤버가 나중에 실행되도록 픽스업을 기록합니다.

RegisterObject(Object, Int64)
사용되지 않음.

개체가 역직렬화될 때 개체를 등록하여 objectID와 연관시킵니다.

RegisterObject(Object, Int64, SerializationInfo)
사용되지 않음.

개체가 역직렬화될 때 개체를 등록하여 objectID와 연관시키고 여기에 사용되는 SerializationInfo를 기록합니다.

RegisterObject(Object, Int64, SerializationInfo, Int64, MemberInfo)
사용되지 않음.

개체의 멤버가 역직렬화될 때 개체의 멤버를 등록하여 objectID와 연관시키고 SerializationInfo를 기록합니다.

RegisterObject(Object, Int64, SerializationInfo, Int64, MemberInfo, Int32[])
사용되지 않음.

개체에 포함된 배열의 멤버가 역직렬화될 때 해당 멤버를 등록하여 objectID와 연관시키고 SerializationInfo를 기록합니다.

ToString()
사용되지 않음.

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상