protected override Expression Bind()
        {
            var frameBinder = new CallFrameBinder();

            var cases = from method in Methods
                        select CreateCallEmitter(method, frameBinder).Bind();

            var defaultCase = Throw(Expressions.ThrowInvalidConversion(), typeof(iObject));

            return(Block(
                       typeof(iObject),
                       frameBinder,
                       Assign(frameBinder.Instance, CallFrame.Expressions.Instance(CallFrame.Expressions.Current())),
                       Assign(frameBinder.Bundle, CallFrame.Expressions.Arguments(CallFrame.Expressions.Current())),
                       Switch(typeof(iObject), Constant(true), defaultCase, null, cases)
                       ));
        }
        protected override Expression Bind()
        {
            var frameBinder = new CallFrameBinder();

            var method = Property(Constant(Lambda), nameof(Lambda.Method));
            var bundle = CallFrame.Expressions.Arguments(CallFrame.Expressions.Current());

            var instance = CallFrame.Expressions.Instance(CallFrame.Expressions.Current()).Cast(Lambda.InstanceType);

            var convertedArgs =
                from p in Lambda.Method.Parameters
                select ConvertArgument(frameBinder.Arguments, p);

            var arguments = new[] { instance }.Concat(convertedArgs);

            return(Block(
                       new[] { frameBinder.Arguments },
                       Assign(frameBinder.Arguments, ArgumentBundle.Expressions.Bind(bundle, method)),
                       Box(Invoke(Constant(Lambda.Lambda), arguments))
                       ));
        }
 private static CallEmitter CreateCallEmitter(MethodMetadata method,
                                              CallFrameBinder frameBinder)
 => method.IsStatic
         ? new StaticCallEmitter(method, frameBinder)
         : new InstanceCallEmitter(method, frameBinder);
Example #4
0
 public InstanceCallEmitter(MethodMetadata method, CallFrameBinder frame)
 {
     Method = method;
     Frame  = frame;
 }
 public StaticCallEmitter(MethodMetadata method, CallFrameBinder frame)
     : base(method, frame)
 {
 }