示例#1
0
        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            var overloads = GetMethods(binder.Name);

            if (overloads == null)
            {
                return(binder.FallbackInvokeMember(this, args));
            }

            if (Disposed)
            {
                return(new DynamicMetaObject(ThrowObjectDisposedException(typeof(object)), BindingRestrictions.GetInstanceRestriction(Expression, Value)));
            }

            var applicable = overloads.Where(o => (o.IsStatic == !HasSelf) && o.ArgumentTypes.Count == args.Length).ToArray();

            if (applicable.Length == 0)
            {
                return(binder.FallbackInvokeMember(this, args));
            }

            TryInvokeMember invoke   = info.TryInvokeMember;
            var             value    = Expression.Parameter(typeof(object), "value");
            var             fallback = binder.FallbackInvokeMember(this, args);
            var             call     = Expression.Block(
                new[] { value },
                Expression.Condition(
                    test:       Expression.Call(Expression.Constant(info), invoke.GetMethodInfo(), GetSelf(), Expression.Constant(applicable), Expression.Constant(args), value),
                    ifTrue:     value,
                    ifFalse:    fallback.Expression)
                );

            return(new DynamicMetaObject(call, BindingRestrictions.GetInstanceRestriction(Expression, Value)));
        }
示例#2
0
            public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
            {
                if (klass.info == null || klass.info.Disposed)
                {
                    return(binder.FallbackInvoke(this, args));
                }

                var constructors = klass.info.Constructors;

                if (constructors == null)
                {
                    return(binder.FallbackInvoke(this, args));
                }

                if (Disposed)
                {
                    return(new DynamicMetaObject(ThrowObjectDisposedException(typeof(object)), BindingRestrictions.GetInstanceRestriction(Expression, Value)));
                }

                var applicable = constructors.Where(o => o.ArgumentTypes.Count == args.Length).ToArray();

                if (applicable.Length == 0)
                {
                    return(binder.FallbackInvoke(this, args));
                }

                TryInvokeMember invoke   = klass.info.TryInvokeMember;
                var             value    = Expression.Parameter(typeof(object), "value");
                var             fallback = binder.FallbackInvoke(this, args);
                var             call     = Expression.Block(
                    new[] { value },
                    Expression.Condition(
                        test:       Expression.Call(Expression.Constant(klass.info), invoke.GetMethodInfo(),
                                                    Expression.Constant(null, typeof(IJavaPeerable)), Expression.Constant(applicable), Expression.Constant(args), value),
                        ifTrue:     value,
                        ifFalse:    fallback.Expression)
                    );

                return(new DynamicMetaObject(call, BindingRestrictions.GetInstanceRestriction(Expression, Value)));
            }