Ejemplo n.º 1
0
        /// <summary>
        /// Serializes a value of type <see cref="T" /> using a specified <see cref="IDataWriter" />.
        /// </summary>
        /// <param name="value">The value to serialize.</param>
        /// <param name="writer">The writer to use.</param>
        public void Serialize(T value, IDataWriter writer)
        {
            var context = writer.Context;

            for (int i = 0; i < OnSerializingCallbacks.Length; i++)
            {
                try
                {
                    OnSerializingCallbacks[i](ref value, context.StreamingContext);
                }
                catch (Exception ex)
                {
                    context.Config.DebugContext.LogException(ex);
                }
            }

            if (ImplementsISerializationCallbackReceiver)
            {
                try
                {
                    UnityEngine.ISerializationCallbackReceiver v = value as UnityEngine.ISerializationCallbackReceiver;
                    v.OnBeforeSerialize();
                    value = (T)v;
                }
                catch (Exception ex)
                {
                    context.Config.DebugContext.LogException(ex);
                }
            }

            try
            {
                this.SerializeImplementation(ref value, writer);
            }
            catch (Exception ex)
            {
                context.Config.DebugContext.LogException(ex);
            }

            for (int i = 0; i < OnSerializedCallbacks.Length; i++)
            {
                try
                {
                    OnSerializedCallbacks[i](ref value, context.StreamingContext);
                }
                catch (Exception ex)
                {
                    context.Config.DebugContext.LogException(ex);
                }
            }
        }
Ejemplo n.º 2
0
        static StackObject *OnAfterDeserialize_1(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            UnityEngine.ISerializationCallbackReceiver instance_of_this_method = (UnityEngine.ISerializationCallbackReceiver) typeof(UnityEngine.ISerializationCallbackReceiver).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.OnAfterDeserialize();

            return(__ret);
        }
        static int _m_OnAfterDeserialize(RealStatePtr L)
        {
            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


            UnityEngine.ISerializationCallbackReceiver __cl_gen_to_be_invoked = (UnityEngine.ISerializationCallbackReceiver)translator.FastGetCSObj(L, 1);


            try {
                {
                    __cl_gen_to_be_invoked.OnAfterDeserialize(  );



                    return(0);
                }
            } catch (System.Exception __gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Deserializes a value of type <see cref="T" /> using a specified <see cref="IDataReader" />.
        /// </summary>
        /// <param name="reader">The reader to use.</param>
        /// <returns>
        /// The deserialized value.
        /// </returns>
        public T Deserialize(IDataReader reader)
        {
            var context = reader.Context;
            T   value   = this.GetUninitializedObject();

            // We allow the above method to return null (for reference types) because of special cases like arrays,
            //  where the size of the array cannot be known yet, and thus we cannot create an object instance at this time.
            //
            // Therefore, those who override GetUninitializedObject and return null must call RegisterReferenceID and InvokeOnDeserializingCallbacks manually.
            if (BaseFormatter <T> .IsValueType)
            {
                this.InvokeOnDeserializingCallbacks(ref value, context);
            }
            else
            {
                if (object.ReferenceEquals(value, null) == false)
                {
                    this.RegisterReferenceID(value, reader);
                    this.InvokeOnDeserializingCallbacks(ref value, context);

                    if (ImplementsIObjectReference)
                    {
                        try
                        {
                            value = (T)(value as IObjectReference).GetRealObject(context.StreamingContext);
                            this.RegisterReferenceID(value, reader);
                        }
                        catch (Exception ex)
                        {
                            context.Config.DebugContext.LogException(ex);
                        }
                    }
                }
            }

            try
            {
                this.DeserializeImplementation(ref value, reader);
            }
            catch (Exception ex)
            {
                context.Config.DebugContext.LogException(ex);
            }

            // The deserialized value might be null, so check for that
            if (BaseFormatter <T> .IsValueType || object.ReferenceEquals(value, null) == false)
            {
                for (int i = 0; i < OnDeserializedCallbacks.Length; i++)
                {
                    try
                    {
                        OnDeserializedCallbacks[i](ref value, context.StreamingContext);
                    }
                    catch (Exception ex)
                    {
                        context.Config.DebugContext.LogException(ex);
                    }
                }

                if (ImplementsIDeserializationCallback)
                {
                    IDeserializationCallback v = value as IDeserializationCallback;
                    v.OnDeserialization(this);
                    value = (T)v;
                }

                if (ImplementsISerializationCallbackReceiver)
                {
                    try
                    {
                        UnityEngine.ISerializationCallbackReceiver v = value as UnityEngine.ISerializationCallbackReceiver;
                        v.OnAfterDeserialize();
                        value = (T)v;
                    }
                    catch (Exception ex)
                    {
                        context.Config.DebugContext.LogException(ex);
                    }
                }
            }

            return(value);
        }