解释代码
using System;using System.Collections.Generic;
using System.Text;
using System.Collections;
using
using System.Xml;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.Reflection;
namespace ConsoleApplication2
{
class TestObjectManager
{
static void Main()
{
SerializationInfo infoClass1 = new SerializationInfo(typeof(SampleClass1), new FormatterConverter()); //使用SerializationInfo实例化一个名为infoClass1的实例
SampleStructure sampleStruct = new SampleStructure();
sampleStruct.VarInt = 100;
infoClass1.AddValue("ObjSampleClass1", sampleStruct);
SerializationInfo infoClass2 = new SerializationInfo(typeof(SampleClass2), new FormatterConverter()); //使用SerializationInfo实例化一个名为infoClass2的实例
infoClass2.AddValue("VarInt", 4);
ObjectManager objMan =new ObjectManager(null,new StreamingContext(StreamingContextStates.All, null));
object objSampleClass1 =FormatterServices.GetUninitializedObject(typeof(SampleClass1)); //
object obj = infoClass1.GetValue("ObjSampleClass1", typeof(SampleStructure)); //
objMan.RegisterObject(obj, 2, null, 1, null);
objMan.RecordFixup(2, typeof(SampleStructure).GetField("VarObject"), 3);
object objSampleClass2 =FormatterServices.GetUninitializedObject(typeof(SampleClass2));//
objMan.RegisterObject(objSampleClass2, 3, infoClass2);
objMan.RegisterObject(objSampleClass1, 1, infoClass1);
Console.WriteLine("VarInt = {0}, VarObject = {1}", ((SampleStructure)obj).VarInt,((SampleStructure)obj).VarObject == null ? "null" : "NOT null");
objMan.DoFixups();
Console.WriteLine("VarInt = {0}, VarObject = {1}",((SampleStructure)obj).VarInt, ((SampleStructure)obj).VarObject == null ? "null" : "NOT null");
SampleClass1 root = (SampleClass1)objMan.GetObject(1);
Console.WriteLine("VarInt = {0}, VarObject = {1}",root.ObjSampleClass1.VarInt,root.ObjSampleClass1.VarObject == null ? "null" : "NOT null");
Console.ReadLine();
}
}
[Serializable]
class SampleClass1 : ISerializable //
{
public SampleStructure ObjSampleClass1;
SampleClass1(SerializationInfo info, StreamingContext context)
{
ObjSampleClass1 = (SampleStructure)info.GetValue("ObjSampleClass1", typeof(SampleStructure));
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
}
}
[Serializable]
struct SampleStructure
{
public int VarInt;
public object VarObject;
}
[Serializable]
class SampleClass2 : ISerializable
{
public int VarInt;
private SampleClass2(SerializationInfo info, StreamingContext context)
{
VarInt = info.GetInt32("VarInt");
}
public void GetObjectData(SerializationInfo info,StreamingContext context)
{
}
}
}
有//的地方麻烦帮我解释下哈!!