/// <summary>
        ///		Gets the IL generator to implement <see cref="MessagePackSerializer{T}.UnpackToCore"/> overrides.
        /// </summary>
        /// <returns>
        ///		The IL generator to implement <see cref="MessagePackSerializer{T}.UnpackToCore"/> overrides.
        /// </returns>
        public override TracingILGenerator GetUnpackToMethodILGenerator()
        {
            if (SerializerDebugging.TraceEnabled)
            {
                SerializerDebugging.TraceEvent("{0}->{1}::{2}", MethodBase.GetCurrentMethod(), this._typeBuilder.Name, "UnpackToCore");
            }

            if (this._unpackToMethodBuilder == null)
            {
#if DEBUG
                Contract.Assert(this._typeBuilder.BaseType != null, "this._typeBuilder.BaseType != null");
#endif // DEBUG
                var baseMethod =
                    this._typeBuilder.BaseType.GetMethod(
                        "UnpackToCore",
                        BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
                        );
                this._unpackToMethodBuilder =
                    this._typeBuilder.DefineMethod(
                        baseMethod.Name,
                        (baseMethod.Attributes | MethodAttributes.Final) & (~MethodAttributes.Abstract),
                        baseMethod.CallingConvention,
                        baseMethod.ReturnType,
                        baseMethod.GetParameters().Select(p => p.ParameterType).ToArray()
                        );
                this._typeBuilder.DefineMethodOverride(
                    this._unpackToMethodBuilder,
                    baseMethod
                    );
            }

            return(new TracingILGenerator(this._unpackToMethodBuilder, SerializerDebugging.ILTraceWriter, this._isDebuggable));
        }
예제 #2
0
        private Delegate EmitMethodEpilogue <T>(ExpressionTreeContext context, Type delegateType, T method, ExpressionConstruct construct)
        {
            if (SerializerDebugging.TraceEnabled)
            {
                SerializerDebugging.TraceEvent("----{0}----", method);
                construct.ToString(SerializerDebugging.ILTraceWriter);
                SerializerDebugging.FlushTraceData();
            }

            var lambda =
                Expression.Lambda(
                    delegateType,
                    construct.Expression,
                    method.ToString(),
                    false,
                    context.GetCurrentParameters()
                    );

#if !NETFX_CORE && !SILVERLIGHT
            if (SerializerDebugging.DumpEnabled)
            {
                var mb =
                    this._typeBuilder.DefineMethod(
                        method.ToString(),
                        MethodAttributes.Public | MethodAttributes.Static,
                        lambda.Type,
                        lambda.Parameters.Select(e => e.Type).ToArray()
                        );
                lambda.CompileToMethod(mb);
            }
#endif
            return(lambda.Compile());
        }
예제 #3
0
        /// <summary>
        ///		Gets the IL generator to implement <see cref="MessagePackSerializer{T}.UnpackToCore"/> overrides.
        /// </summary>
        /// <returns>
        ///		The IL generator to implement <see cref="MessagePackSerializer{T}.UnpackToCore"/> overrides.
        /// </returns>
        public override TracingILGenerator GetUnpackToMethodILGenerator()
        {
            if (SerializerDebugging.TraceEnabled)
            {
                SerializerDebugging.TraceEvent("{0}->{1}::{2}", MethodBase.GetCurrentMethod(), this._typeBuilder.Name, this._unpackToMethodBuilder);
            }

            if (this._unpackToMethodBuilder == null)
            {
                this._unpackToMethodBuilder =
                    this._typeBuilder.DefineMethod(
                        "UnpackToCore",
                        MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.Final,
                        CallingConventions.HasThis,
                        null,
                        new[] { typeof(Unpacker), this._targetType }
                        );
#if DEBUG
                Contract.Assert(this._typeBuilder.BaseType != null, "this._typeBuilder.BaseType != null");
#endif
                this._typeBuilder.DefineMethodOverride(
                    this._unpackToMethodBuilder,
                    this._typeBuilder.BaseType.GetMethod(
                        this._unpackToMethodBuilder.Name,
                        BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
                        )
                    );
            }

            return(new TracingILGenerator(this._unpackToMethodBuilder, SerializerDebugging.ILTraceWriter, this._isDebuggable));
        }
예제 #4
0
        /// <summary>
        ///		Gets the IL generator to implement CreateInstance(int) overrides.
        /// </summary>
        /// <param name="declaration">The virtual method declaration to be overriden.</param>
        /// <returns>
        ///		The IL generator to implement CreateInstance(int) overrides.
        ///		This value will not be <c>null</c>.
        /// </returns>
        public override TracingILGenerator GetCreateInstanceMethodILGenerator(MethodInfo declaration)
        {
            if (SerializerDebugging.TraceEnabled)
            {
                SerializerDebugging.TraceEvent("{0}->{1}::{2}", MethodBase.GetCurrentMethod(), this._typeBuilder.Name, this._createInstanceMethodBuilder);
            }

            if (this._createInstanceMethodBuilder == null)
            {
                this._createInstanceMethodBuilder =
                    this._typeBuilder.DefineMethod(
                        "CreateInstance",
                        MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.HideBySig,
                        CallingConventions.HasThis,
                        this._targetType,
                        CreateInstanceParameterTypes
                        );
#if DEBUG
                Contract.Assert(this._typeBuilder.BaseType != null, "this._typeBuilder.BaseType != null");
#endif
                this._typeBuilder.DefineMethodOverride(
                    this._createInstanceMethodBuilder,
                    this._typeBuilder.BaseType.GetMethod(
                        this._createInstanceMethodBuilder.Name,
                        BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
                        )
                    );
            }

            return(new TracingILGenerator(this._createInstanceMethodBuilder, SerializerDebugging.ILTraceWriter, this._isDebuggable));
        }
예제 #5
0
        /// <summary>
        ///		Gets the IL generator to implement AddItem(TCollection, TItem) or AddItem(TCollection, object) overrides.
        /// </summary>
        /// <param name="declaration">The virtual method declaration to be overriden.</param>
        /// <returns>
        ///		The IL generator to implement AddItem(TCollection, TItem) or AddItem(TCollection, object) overrides.
        ///		This value will not be <c>null</c>.
        /// </returns>
        public override TracingILGenerator GetAddItemMethodILGenerator(MethodInfo declaration)
        {
            if (SerializerDebugging.TraceEnabled)
            {
                SerializerDebugging.TraceEvent("{0}::{1}", MethodBase.GetCurrentMethod(), "AddItem");
            }

            if (this._addItemMethod == null)
            {
                this._addItemMethod =
                    new DynamicMethod(
                        "AddItem",
                        null,
                        (this._traits.DetailedCollectionType == CollectionDetailedKind.GenericDictionary
#if !NETFX_40 && !NETFX_35 && !SILVERLIGHT
                         || this._traits.DetailedCollectionType == CollectionDetailedKind.GenericReadOnlyDictionary
#endif // !NETFX_40 && !NETFX_35 && !SILVERLIGHT
                        )
                                                ? new[] { typeof(SerializationContext), this._targetType, this._traits.ElementType.GetGenericArguments()[0], this._traits.ElementType.GetGenericArguments()[1] }
                                                : new[] { typeof(SerializationContext), this._targetType, this._traits.ElementType }
                        );
            }

            return(new TracingILGenerator(this._addItemMethod, SerializerDebugging.ILTraceWriter));
        }
        public override TracingILGenerator GetUnpackFromUnderlyingValueMethodILGenerator()
        {
            if (SerializerDebugging.TraceEnabled)
            {
                SerializerDebugging.TraceEvent("{0}::{1}", MethodBase.GetCurrentMethod(), this._unpackFromUnderlyingValueMethod);
            }

            return(new TracingILGenerator(this._unpackFromUnderlyingValueMethod, SerializerDebugging.ILTraceWriter));
        }
예제 #7
0
        public override TracingILGenerator GetUnpackFromUnderlyingValueMethodILGenerator()
        {
            if (SerializerDebugging.TraceEnabled)
            {
                SerializerDebugging.TraceEvent("{0}->{1}::{2}", MethodBase.GetCurrentMethod(), this._typeBuilder.Name, this._unpackFromUnderlyingValueMethodBuilder);
            }

            return(new TracingILGenerator(this._unpackFromUnderlyingValueMethodBuilder, SerializerDebugging.ILTraceWriter, this._isDebuggable));
        }
예제 #8
0
        /// <summary>
        ///		Gets the IL generator to implement <see cref="MessagePackSerializer{T}.UnpackToCore"/> overrides.
        /// </summary>
        /// <returns>
        ///		The IL generator to implement <see cref="MessagePackSerializer{T}.UnpackToCore"/> overrides.
        /// </returns>
        public override TracingILGenerator GetUnpackToMethodILGenerator()
        {
            if (SerializerDebugging.TraceEnabled)
            {
                SerializerDebugging.TraceEvent("{0}::{1}", MethodBase.GetCurrentMethod(), this._unpackToMethod);
            }

            if (this._unpackToMethod == null)
            {
                this._unpackToMethod = new DynamicMethod(
                    "UnpackToCore",
                    null,
                    new[] { typeof(SerializationContext), typeof(Unpacker), this._targetType });
            }

            return(new TracingILGenerator(this._unpackToMethod, SerializerDebugging.ILTraceWriter));
        }
예제 #9
0
        /// <summary>
        ///		Gets the IL generator to implement <see cref="MessagePackSerializer{T}.UnpackFromCore"/> overrides.
        /// </summary>
        /// <returns>
        ///		The IL generator to implement <see cref="MessagePackSerializer{T}.UnpackFromCore"/> overrides.
        ///		This value will not be <c>null</c>.
        /// </returns>
        public override TracingILGenerator GetUnpackFromMethodILGenerator()
        {
            if (SerializerDebugging.TraceEnabled)
            {
                SerializerDebugging.TraceEvent("{0}::{1}", MethodBase.GetCurrentMethod(), this._unpackFromMethod);
            }

            if (this._unpackFromMethod == null)
            {
                this._unpackFromMethod =
                    new DynamicMethod(
                        "UnpackFromCore",
                        this._targetType,
                        UnpackFromCoreParameterTypes
                        );
            }

            return(new TracingILGenerator(this._unpackFromMethod, SerializerDebugging.ILTraceWriter));
        }
예제 #10
0
        /// <summary>
        ///		Gets the IL generator to implement private static RestoreSchema() method.
        /// </summary>
        /// <returns>
        ///		The IL generator to implement RestoreSchema() static method.
        ///		This value will not be <c>null</c>.
        /// </returns>
        public override TracingILGenerator GetRestoreSchemaMethodILGenerator()
        {
            if (SerializerDebugging.TraceEnabled)
            {
                SerializerDebugging.TraceEvent("{0}::{1}", MethodBase.GetCurrentMethod(), this._restoreSchemaMethod);
            }

            if (this._restoreSchemaMethod == null)
            {
                this._restoreSchemaMethod =
                    new DynamicMethod(
                        "RestoreSchema",
                        typeof(PolymorphismSchema),
                        ReflectionAbstractions.EmptyTypes
                        );
            }

            return(new TracingILGenerator(this._restoreSchemaMethod, SerializerDebugging.ILTraceWriter));
        }
예제 #11
0
        /// <summary>
        ///		Gets the IL generator to implement CreateInstance(int) overrides.
        /// </summary>
        /// <param name="declaration">The virtual method declaration to be overriden.</param>
        /// <returns>
        ///		The IL generator to implement CreateInstance(int) overrides.
        ///		This value will not be <c>null</c>.
        /// </returns>
        public override TracingILGenerator GetCreateInstanceMethodILGenerator(MethodInfo declaration)
        {
            if (SerializerDebugging.TraceEnabled)
            {
                SerializerDebugging.TraceEvent("{0}::{1}", MethodBase.GetCurrentMethod(), this._createInstanceMethod);
            }

            if (this._createInstanceMethod == null)
            {
                this._createInstanceMethod =
                    new DynamicMethod(
                        "CreateInstance",
                        this._targetType,
                        CreateInstanceParameterTypes
                        );
            }

            return(new TracingILGenerator(this._createInstanceMethod, SerializerDebugging.ILTraceWriter));
        }
예제 #12
0
        /// <summary>
        ///		Gets the IL generator to implement AddItem(TCollection, TItem) or AddItem(TCollection, object) overrides.
        /// </summary>
        /// <param name="declaration">The virtual method declaration to be overriden.</param>
        /// <returns>
        ///		The IL generator to implement AddItem(TCollection, TItem) or AddItem(TCollection, object) overrides.
        ///		This value will not be <c>null</c>.
        /// </returns>
        public override TracingILGenerator GetAddItemMethodILGenerator(MethodInfo declaration)
        {
            if (SerializerDebugging.TraceEnabled)
            {
                SerializerDebugging.TraceEvent("{0}::{1}", MethodBase.GetCurrentMethod(), this._addItemMethod);
            }

            if (this._addItemMethod == null)
            {
                this._addItemMethod =
                    new DynamicMethod(
                        "AddItem",
                        null,
                        new[] { typeof(SerializationContext), this._targetType, this._traits.ElementType }
                        );
            }

            return(new TracingILGenerator(this._addItemMethod, SerializerDebugging.ILTraceWriter));
        }
        /// <summary>
        ///		Gets the IL generator to implement private static RestoreSchema() method.
        /// </summary>
        /// <returns>
        ///		The IL generator to implement RestoreSchema() static method.
        ///		This value will not be <c>null</c>.
        /// </returns>
        public override TracingILGenerator GetRestoreSchemaMethodILGenerator()
        {
            if (SerializerDebugging.TraceEnabled)
            {
                SerializerDebugging.TraceEvent("{0}->{1}::{2}", MethodBase.GetCurrentMethod(), this._typeBuilder.Name, "RestoreSchema");
            }

            if (this._restoreSchemaMethodBuilder == null)
            {
                this._restoreSchemaMethodBuilder =
                    this._typeBuilder.DefineMethod(
                        "RestoreSchema",
                        MethodAttributes.Private | MethodAttributes.Static | MethodAttributes.HideBySig,
                        CallingConventions.Standard,
                        typeof(PolymorphismSchema),
                        ReflectionAbstractions.EmptyTypes
                        );
            }

            return(new TracingILGenerator(this._restoreSchemaMethodBuilder, SerializerDebugging.ILTraceWriter, this._isDebuggable));
        }