Пример #1
0
        /// <include file='Doc/Common.xml' path='/docs/method[@name="OnDeserialization"]/*'/>
        public virtual void OnDeserialization(object sender)
        {
            if (instance == null)
            {
                return;
            }

            object real_object = serInfo.GetValue(ClrRealObjectSerializationInfoKey, typeof(object));

            if (real_object != null)
            {
                // if we have serialized CLR real object, populate the instance now
                if (instance is __PHP_Incomplete_Class)
                {
                    Serialization.SetProperty(
                        instance,
                        ClrRealObjectSerializationInfoKey,
                        ClrObject.WrapRealObject(real_object),
                        context.ScriptContext);
                }
                else if (instance is IClrValue)
                {
                    Type      type  = instance.GetType(); // generic type ClrValue<T>
                    FieldInfo field = type.GetField("realValue");
                    Debug.Assert(field != null);
                    field.SetValue(instance, real_object);
                }
                else
                {
                    ((ClrObject)instance).SetRealObject(real_object);
                }
            }

            // deserialize fields
            SerializationInfoEnumerator enumerator = serInfo.GetEnumerator();

            while (enumerator.MoveNext())
            {
                string name = enumerator.Name;

                if (name != __PHP_Incomplete_Class.ClassNameFieldName &&
                    name != ClrRealObjectSerializationInfoKey)
                {
                    Serialization.SetProperty(
                        instance,
                        name,
                        UnwrapPropertyValue(enumerator.Value),
                        context.ScriptContext);
                }
            }

            Serialization.DebugInstanceDeserialized(instance, true);

            instance.Wakeup(context.ClassContext, context.ScriptContext);
        }
Пример #2
0
			/// <summary>
			/// Builds a <see cref="DObject"/> from atoms (the object itself given as parameter).
			/// </summary>
			/// <param name="obj">The instance.</param>
			private void BuildDObject(DObject obj)
			{
				bool serializable = ((bool)atoms[atomCounter++] == true);

				if (serializable && obj.RealObject is Library.SPL.Serializable)
				{
					// pass the serialized data to unserialize
					context.Stack.AddFrame(BuildObjectGraph());
					obj.InvokeMethod("unserialize", null, context);
					return;
				}

				while (atoms[atomCounter] != delimiter)
				{
					string property_name = (string)BuildObjectGraph();
					object property_value = BuildObjectGraph();

					Debug.Assert(property_name != null);
					Serialization.SetProperty(obj, property_name, property_value, context);
				}
				atomCounter++; // for the delimiter

				// invoke __wakeup on the deserialized instance
				obj.Wakeup(ClassContext, context);
			}