/// <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()); } } }
/// <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()); } } }
public void SetCurrentMethod(Type targetType, EnumSerializerMethod method) { this.This = Expression.Parameter( typeof(ExpressionCallbackEnumMessagePackSerializer <>).MakeGenericType(targetType), "this" ); this._currentParamters = this.GetParameters(targetType, method).ToArray(); }
protected override void EmitMethodEpilogue(ExpressionTreeContext context, EnumSerializerMethod method, ExpressionConstruct construct) { if (construct == null) { return; } context.SetDelegate(method, EmitMethodEpilogue(context, ExpressionTreeContext.CreateDelegateType <TObject>(method), method, construct)); }
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()); } } }
/// <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()); } } }
protected override void EmitMethodPrologue(ExpressionTreeContext context, EnumSerializerMethod method) { context.Reset(typeof(TObject)); context.SetCurrentMethod(typeof(TObject), method); }
protected override void EmitMethodEpilogue(TContext context, EnumSerializerMethod enumSerializerMethod, ILConstruct construct) { EmitMethodEpilogue(context, construct); }
protected override void EmitMethodEpilogue(TContext context, EnumSerializerMethod enumSerializerMethod, TConstruct construct) { Contract.Requires(context != null); Contract.Requires(Enum.IsDefined(typeof(EnumSerializerMethod), enumSerializerMethod)); Contract.Requires(construct != null); }
public void SetCurrentMethod(Type targetType, EnumSerializerMethod method) { this._currentParamters = this.GetParameters(targetType, method).ToArray(); }
protected override void EmitMethodPrologue(TContext context, EnumSerializerMethod method) { Contract.Requires(context != null); Contract.Requires(Enum.IsDefined(typeof(EnumSerializerMethod), method)); }