protected override void EmitMethodPrologue(TContext context, SerializerMethod method) { switch (method) { case SerializerMethod.PackToCore: { context.IL = context.Emitter.GetPackToMethodILGenerator(); break; } case SerializerMethod.UnpackFromCore: { context.IL = context.Emitter.GetUnpackFromMethodILGenerator(); break; } case SerializerMethod.UnpackToCore: { context.IL = context.Emitter.GetUnpackToMethodILGenerator(); 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(SerializerMethod method, Delegate @delegate) { switch (method) { case SerializerMethod.PackToCore: { this._packToCore = @delegate; break; } case SerializerMethod.UnpackFromCore: { this._unpackFromCore = @delegate; break; } case SerializerMethod.UnpackToCore: { this._unpackToCore = @delegate; 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>(SerializerMethod method) { switch (method) { case SerializerMethod.PackToCore: { return(typeof(Action <ExpressionCallbackMessagePackSerializer <TObject>, SerializationContext, Packer, TObject>)); } case SerializerMethod.UnpackFromCore: { return(typeof(Func <ExpressionCallbackMessagePackSerializer <TObject>, SerializationContext, Unpacker, TObject>)); } case SerializerMethod.UnpackToCore: { return(typeof(Action <ExpressionCallbackMessagePackSerializer <TObject>, SerializationContext, Unpacker, TObject>)); } default: { throw new ArgumentOutOfRangeException("method", method.ToString()); } } }
public void SetCurrentMethod(Type targetType, SerializerMethod method) { this.This = Expression.Parameter( typeof(ExpressionCallbackMessagePackSerializer <>).MakeGenericType(targetType), "this" ); this._currentParamters = this.GetParameters(method).ToArray(); }
protected override void EmitMethodEpilogue(ExpressionTreeContext context, SerializerMethod method, ExpressionConstruct construct) { if (construct == null) { return; } context.SetDelegate(method, EmitMethodEpilogue(context, ExpressionTreeContext.CreateDelegateType <TObject>(method), method, construct)); }
/// <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> /// <param name="serializerType">The type of callback serializer.</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>(SerializerMethod method, Type serializerType) { switch (method) { case SerializerMethod.PackToCore: { return (typeof(Action <, , ,>).MakeGenericType( serializerType, typeof(SerializationContext), typeof(Packer), typeof(TObject) )); } case SerializerMethod.UnpackFromCore: { return (typeof(Func <, , ,>).MakeGenericType( serializerType, typeof(SerializationContext), typeof(Unpacker), typeof(TObject) )); } case SerializerMethod.UnpackToCore: { return (typeof(Action <, , ,>).MakeGenericType( serializerType, typeof(SerializationContext), typeof(Unpacker), typeof(TObject) )); } default: { throw new ArgumentOutOfRangeException("method", method.ToString()); } } }
/// <summary> /// Gets the <see cref="ParameterExpression"/>s for specified method. /// </summary> /// <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(SerializerMethod method) { yield return(this.This.Expression as ParameterExpression); yield return(this._context.Expression as ParameterExpression); switch (method) { case SerializerMethod.PackToCore: { yield return(this.Packer.Expression as ParameterExpression); yield return(this.PackToTarget.Expression as ParameterExpression); break; } case SerializerMethod.UnpackFromCore: { yield return(this.Unpacker.Expression as ParameterExpression); break; } case SerializerMethod.UnpackToCore: { yield return(this.Unpacker.Expression as ParameterExpression); yield return(this.UnpackToTarget.Expression as ParameterExpression); break; } default: { throw new ArgumentOutOfRangeException("method", method.ToString()); } } }
protected override void EmitMethodPrologue(ExpressionTreeContext context, SerializerMethod method) { context.Reset(typeof(TObject)); context.SetCurrentMethod(typeof(TObject), method); }
protected override void EmitMethodEpilogue(TContext context, SerializerMethod method, ILConstruct construct) { EmitMethodEpilogue(context, construct); }
protected override void EmitMethodEpilogue(TContext context, SerializerMethod method, TConstruct construct) { Contract.Requires(context != null); Contract.Requires(Enum.IsDefined(typeof(SerializationMethod), method)); Contract.Requires(construct != null); }
public void SetCurrentMethod(SerializerMethod method) { this._currentParamters = this.GetParameters(method).ToArray(); }