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 使用してオブジェクト グラフをウォークし、各オブジェクトを 1 回だけ走査する方法を示しています。

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

注釈

逆シリアル化中に、 を照会ObjectManagerして、Formatterシリアル化されたストリーム内のオブジェクトへの参照が、既に逆シリアル化されているオブジェクト (後方参照) を参照しているか、まだ逆シリアル化されていないオブジェクト (前方参照) を参照しているかを判断します。 シリアル化されたストリーム内の参照が前方参照である場合、 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 を実装する任意の登録されたオブジェクトに逆シリアル化イベントを発生させます。

RaiseOnDeserializingEvent(Object)
古い.

OnDeserializingAttribute でマークされたメソッドを呼び出します。

RecordArrayElementFixup(Int64, Int32, Int64)
古い.

配列内の 1 つの要素に対するフィックスアップを記録します。

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)

適用対象