本文整理汇总了C#中System.Runtime.Serialization.ObjectManager.GetObjectRecord方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectManager.GetObjectRecord方法的具体用法?C# ObjectManager.GetObjectRecord怎么用?C# ObjectManager.GetObjectRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.Serialization.ObjectManager
的用法示例。
在下文中一共展示了ObjectManager.GetObjectRecord方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadData
public bool LoadData (ObjectManager manager, ISurrogateSelector selector, StreamingContext context)
{
if (Info != null)
{
if (Surrogate != null) {
object new_obj = Surrogate.SetObjectData (ObjectInstance, Info, context, SurrogateSelector);
if (new_obj != null)
ObjectInstance = new_obj;
Status = ObjectRecordStatus.ReferenceSolved;
} else if (ObjectInstance is ISerializable) {
object[] pars = new object[] {Info, context};
ConstructorInfo con = ObjectInstance.GetType().GetConstructor (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof (SerializationInfo), typeof (StreamingContext) }, null );
if (con == null) throw new SerializationException ("The constructor to deserialize an object of type " + ObjectInstance.GetType().FullName + " was not found.");
con.Invoke (ObjectInstance, pars);
} else {
throw new SerializationException ("No surrogate selector was found for type " + ObjectInstance.GetType().FullName);
}
Info = null;
}
if (ObjectInstance is IObjectReference && Status != ObjectRecordStatus.ReferenceSolved)
{
try {
ObjectInstance = ((IObjectReference)ObjectInstance).GetRealObject(context);
int n = 100;
while (ObjectInstance is IObjectReference && n > 0) {
object ob = ((IObjectReference)ObjectInstance).GetRealObject (context);
if (ob == ObjectInstance)
break;
ObjectInstance = ob;
n--;
}
if (n == 0)
throw new SerializationException ("The implementation of the IObjectReference interface returns too many nested references to other objects that implement IObjectReference.");
Status = ObjectRecordStatus.ReferenceSolved;
}
catch (NullReferenceException) {
// Give a second chance
return false;
}
}
if (Member != null)
{
// If this object is a value object embedded in another object, the parent
// object must be updated
ObjectRecord containerRecord = manager.GetObjectRecord (IdOfContainingObj);
containerRecord.SetMemberValue (manager, Member, ObjectInstance);
}
else if (ArrayIndex != null)
{
ObjectRecord containerRecord = manager.GetObjectRecord (IdOfContainingObj);
containerRecord.SetArrayValue (manager, ObjectInstance, ArrayIndex);
}
return true;
}
示例2: SetMemberValue
public void SetMemberValue (ObjectManager manager, MemberInfo member, object value)
{
if (member is FieldInfo)
((FieldInfo)member).SetValue (ObjectInstance, value);
else if (member is PropertyInfo)
((PropertyInfo)member).SetValue (ObjectInstance, value, null);
else throw new SerializationException ("Cannot perform fixup");
if (Member != null)
{
ObjectRecord containerRecord = manager.GetObjectRecord (IdOfContainingObj);
if (containerRecord.IsRegistered)
containerRecord.SetMemberValue (manager, Member, ObjectInstance);
}
else if (ArrayIndex != null)
{
ObjectRecord containerRecord = manager.GetObjectRecord (IdOfContainingObj);
if (containerRecord.IsRegistered)
containerRecord.SetArrayValue (manager, ObjectInstance, ArrayIndex);
}
}