当前位置: 首页>>代码示例>>C#>>正文


C# ObjectManager.GetObjectRecord方法代码示例

本文整理汇总了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;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:60,代码来源:ObjectManager.cs

示例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);
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:21,代码来源:ObjectManager.cs


注:本文中的System.Runtime.Serialization.ObjectManager.GetObjectRecord方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。