Exemplo n.º 1
0
        public static bool TryBindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result)
        {
            Requires.NotNull(binder, nameof(binder));
            Requires.NotNull(instance, nameof(instance));
            Requires.NotNull(args, nameof(args));

            if (TryGetMetaObject(ref instance))
            {
                result = instance.BindInvokeMember(binder, args);
                return(true);
            }

            result = null;
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tries to perform binding of the dynamic invoke member operation.
        /// </summary>
        /// <param name="binder">An instance of the <see cref="InvokeMemberBinder"/> that represents the details of the dynamic operation.</param>
        /// <param name="instance">The target of the dynamic operation. </param>
        /// <param name="args">An array of <see cref="DynamicMetaObject"/> instances - arguments to the invoke member operation.</param>
        /// <param name="result">The new <see cref="DynamicMetaObject"/> representing the result of the binding.</param>
        /// <returns>true if operation was bound successfully; otherwise, false.</returns>
        public static bool TryBindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result)
        {
            ContractUtils.RequiresNotNull(binder, "binder");
            ContractUtils.RequiresNotNull(instance, "instance");
            ContractUtils.RequiresNotNull(args, "args");

            if (TryGetMetaObject(ref instance))
            {
                result = instance.BindInvokeMember(binder, args);
                return(true);
            }
            else
            {
                result = null;
                return(false);
            }
        }
Exemplo n.º 3
0
        public static bool TryBindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result)
        {
            ContractUtils.RequiresNotNull(binder, "binder");
            ContractUtils.RequiresNotNull(instance, "instance");
            ContractUtils.RequiresNotNull(args, "args");

            if (TryGetMetaObject(ref instance))
            {
                //
                // Demand Full Trust to proceed with the binding.
                //

                new PermissionSet(PermissionState.Unrestricted).Demand();

                result = instance.BindInvokeMember(binder, args);
                return(true);
            }
            else
            {
                result = null;
                return(false);
            }
        }
Exemplo n.º 4
0
 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
 {
     return(AddRestrictions(_metaForwardee.BindInvokeMember(binder, args)));
 }
Exemplo n.º 5
0
 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
 {
     // Whether or not to try the parent object first...
     return(binder.FallbackInvokeMember(this, args, innerMetaObject.BindInvokeMember(binder, args)));
     //return innerMetaObject.BindInvokeMember(binder, args);
 }
Exemplo n.º 6
0
 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
 {
     return(scriptItem.PostProcessBindResult(metaDynamic.BindInvokeMember(binder, args)));
 }
Exemplo n.º 7
0
 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) => _innerMetaObject.BindInvokeMember(binder, args);
Exemplo n.º 8
0
        private static dynamic Match(object rawLeft, object rawRight, NovaExpressionType novaBinaryNodeType, object rawScope)
        {
            var scope = (NovaScope)rawScope;

            var left  = CompilerServices.CompileExpression((Expression)rawLeft, scope);
            var right = CompilerServices.CompileExpression((Expression)rawRight, scope);

            var NovaName = "=~";
            var clrName  = InteropBinder.ToClrOperatorName(NovaName);

            if (left is NovaInstance)
            {
                var lo = (NovaInstance)left;
                DynamicMetaObject dmo = lo.GetMetaObject(Expression.Constant(left));
                if (InteropBinder.InvokeMember.SearchForFunction(lo.Class, NovaName, lo, L(Arg(right)), true) != null)
                {
                    if (novaBinaryNodeType == NovaExpressionType.NotMatch)
                    {
                        return(!dmo.BindInvokeMember(new InteropBinder.InvokeMember(NovaName, new CallInfo(1), scope),
                                                     _DMO(DMO(scope), DMO(Arg(right)))));
                    }
                    return(dmo.BindInvokeMember(new InteropBinder.InvokeMember(NovaName, new CallInfo(1), scope),
                                                _DMO(DMO(scope), DMO(Arg(right)))));
                }
                if (InteropBinder.InvokeMember.SearchForFunction(lo.Class, clrName, lo, L(Arg(right)), true) != null)
                {
                    if (novaBinaryNodeType == NovaExpressionType.NotMatch)
                    {
                        return(!dmo.BindInvokeMember(new InteropBinder.InvokeMember(clrName, new CallInfo(1), scope),
                                                     _DMO(DMO(scope), DMO(Arg(right)))));
                    }
                    return(dmo.BindInvokeMember(new InteropBinder.InvokeMember(clrName, new CallInfo(1), scope),
                                                _DMO(DMO(scope), DMO(Arg(right)))));
                }
            }

            var Value = Nova.Box(left);

            if (Value.Class != null)
            {
                var _dmo = Value.GetMetaObject(Expression.Constant(Value));
                if (InteropBinder.InvokeMember.SearchForFunction(Value.Class, NovaName, Value, L(Arg(right)), true) !=
                    null)
                {
                    if (novaBinaryNodeType == NovaExpressionType.NotMatch)
                    {
                        return(!_dmo.BindInvokeMember(new InteropBinder.InvokeMember(NovaName, new CallInfo(1), scope),
                                                      _DMO(DMO(scope), DMO(Arg(right)))));
                    }
                    return(_dmo.BindInvokeMember(new InteropBinder.InvokeMember(NovaName, new CallInfo(1), scope),
                                                 _DMO(DMO(scope), DMO(Arg(right)))));
                }
                if (InteropBinder.InvokeMember.SearchForFunction(Value.Class, clrName, Value, L(Arg(right)), true) !=
                    null)
                {
                    if (novaBinaryNodeType == NovaExpressionType.NotMatch)
                    {
                        return(!_dmo.BindInvokeMember(new InteropBinder.InvokeMember(clrName, new CallInfo(1), scope),
                                                      _DMO(DMO(scope), DMO(Arg(right)))));
                    }
                    return(_dmo.BindInvokeMember(new InteropBinder.InvokeMember(clrName, new CallInfo(1), scope),
                                                 _DMO(DMO(scope), DMO(Arg(right)))));
                }
            }

            if (!(left is Regex || right is Regex))
            {
                return(null);
            }

            var left1 = left as Regex;
            var regex = left1 ?? (Regex)right;

            var str = (left is Regex) ? (string)right : (string)left;

            if (!regex.Match(str).Success)
            {
                return(novaBinaryNodeType == NovaExpressionType.NotMatch);
            }
            var groups = regex.Match(str).Groups;

            foreach (var groupName in regex.GetGroupNames())
            {
                scope[groupName] = groups[groupName].Value;
            }


            return(novaBinaryNodeType == NovaExpressionType.Match);
        }
            public static void TestBindParams(DynamicMetaObject target)
            {
                string methodName = "ToString";

                object[] arguments = new object[] { };

                InvokeMemberBinder binder = new TestInvokeMemberBinder(methodName, arguments.Length);

                DynamicMetaObject[] args = new DynamicMetaObject[arguments.Length];

                ExceptionTestHelper.ExpectException <ArgumentNullException>(() => { var result = target.BindInvokeMember(null, args); });
                ExceptionTestHelper.ExpectException <ArgumentNullException>(() => { var result = target.BindInvokeMember(binder, null); });
            }
Exemplo n.º 10
0
        public static bool TryBindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result) {
            ContractUtils.RequiresNotNull(binder, "binder");
            ContractUtils.RequiresNotNull(instance, "instance");
            ContractUtils.RequiresNotNull(args, "args");

            if (TryGetMetaObject(ref instance)) {
                //
                // Demand Full Trust to proceed with the binding.
                //

                new PermissionSet(PermissionState.Unrestricted).Demand();

                result = instance.BindInvokeMember(binder, args);
                return true;
            } else {
                result = null;
                return false;
            }
        }
Exemplo n.º 11
0
 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
 {
     return(binder.FallbackInvokeMember(_baseMetaObject,
                                        args,
                                        AddTypeRestrictions(_metaObject.BindInvokeMember(binder, args))));
 }
Exemplo n.º 12
0
 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
 {
     return(metaObject.BindInvokeMember(binder, args));
 }
        /// <summary>
        /// Performs the binding of the dynamic invoke member operation.
        /// </summary>
        /// <param name="target">The target of the dynamic invoke member operation.</param>
        /// <param name="args">An array of arguments of the dynamic invoke member operation.</param>
        /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
        public sealed override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) {
            ContractUtils.RequiresNotNull(target, "target");
            ContractUtils.RequiresNotNullItems(args, "args");

            return target.BindInvokeMember(this, args);
        }