Ejemplo n.º 1
0
        /// <summary>
        ///		Gets the <see cref="ParameterExpression"/>s for specified method.
        /// </summary>
        /// <param name="targetType">The type of the serialization target.</param>
        /// <param name="method">The method to be created.</param>
        /// <returns>
        ///		The <see cref="ParameterExpression"/>s for specified method.
        ///		This value will not be <c>null</c>.
        /// </returns>
        private IEnumerable <ParameterExpression> GetParameters(Type targetType, EnumSerializerMethod method)
        {
            yield return(this.This.Expression as ParameterExpression);

            switch (method)
            {
            case EnumSerializerMethod.PackUnderlyingValueTo:
            {
                yield return(this.Packer.Expression as ParameterExpression);

                yield return(Expression.Parameter(targetType, "enumValue"));

                break;
            }

            case EnumSerializerMethod.UnpackFromUnderlyingValue:
            {
                yield return(Expression.Parameter(typeof(MessagePackObject), "messagePackObject"));

                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException("method", method.ToString());
            }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///		Creates the type of the delegate.
        /// </summary>
        /// <typeparam name="TObject">The type of serialization target.</typeparam>
        /// <param name="method">The method to be created.</param>
        /// <returns>
        ///		The <see cref="Type"/> of delegate which can refer to the generating method.
        ///		This value will not be <c>null</c>.
        /// </returns>
        /// <exception cref="InvalidOperationException">
        ///		<paramref name="method"/> is unknown.
        /// </exception>
        public static Type CreateDelegateType <TObject>(EnumSerializerMethod method)
        {
            switch (method)
            {
            case EnumSerializerMethod.PackUnderlyingValueTo:
            {
                return
                    (typeof(Action <, ,>)
                     .MakeGenericType(
                         typeof(ExpressionCallbackEnumMessagePackSerializer <>).MakeGenericType(typeof(TObject)),
                         typeof(Packer),
                         typeof(TObject)
                         ));
            }

            case EnumSerializerMethod.UnpackFromUnderlyingValue:
            {
                return
                    (typeof(Func <, ,>)
                     .MakeGenericType(
                         typeof(ExpressionCallbackEnumMessagePackSerializer <>).MakeGenericType(typeof(TObject)),
                         typeof(MessagePackObject),
                         typeof(TObject)
                         ));
            }

            default:
            {
                throw new ArgumentOutOfRangeException("method", method.ToString());
            }
            }
        }
        protected override void EmitMethodPrologue(TContext context, EnumSerializerMethod method)
        {
            switch (method)
            {
            case EnumSerializerMethod.PackUnderlyingValueTo:
            {
                context.IL = context.EnumEmitter.GetPackUnderyingValueToMethodILGenerator();
                break;
            }

            case EnumSerializerMethod.UnpackFromUnderlyingValue:
            {
                context.IL = context.EnumEmitter.GetUnpackFromUnderlyingValueMethodILGenerator();
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException("method", method.ToString());
            }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///		Sets the specified delegate object for specified method.
        /// </summary>
        /// <param name="method">The method to be created.</param>
        /// <param name="delegate">The delegate which refers the generated method.</param>
        public void SetDelegate(EnumSerializerMethod method, Delegate @delegate)
        {
            switch (method)
            {
            case EnumSerializerMethod.PackUnderlyingValueTo:
            {
                this._packUnderyingValueTo = @delegate;
                break;
            }

            case EnumSerializerMethod.UnpackFromUnderlyingValue:
            {
                this._unpackFromUnderlyingValue = @delegate;
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException("method", method.ToString());
            }
            }
        }