Example #1
0
 public static DynamicMetaObject /*!*/ Bind(DynamicMetaObject /*!*/ context, UnaryOperationBinder /*!*/ binder,
                                            DynamicMetaObject /*!*/ target, Func <DynamicMetaObject, DynamicMetaObject> /*!*/ fallback)
 {
     return(InvokeMember.Bind(context, RubyUtils.MapOperator(binder.Operation), _CallInfo, binder, target, DynamicMetaObject.EmptyMetaObjects,
                              (trgt, _) => fallback(trgt)
                              ));
 }
Example #2
0
 public static DynamicMetaObject /*!*/ Bind(DynamicMetaObject /*!*/ context, BinaryOperationBinder /*!*/ binder,
                                            DynamicMetaObject /*!*/ target, DynamicMetaObject /*!*/ arg,
                                            Func <DynamicMetaObject, DynamicMetaObject, DynamicMetaObject> /*!*/ fallback)
 {
     return(InvokeMember.Bind(context, RubyUtils.MapOperator(binder.Operation), _CallInfo, binder, target, new[] { arg },
                              (trgt, args) => fallback(trgt, args[0])
                              ));
 }
Example #3
0
            public override DynamicMetaObject /*!*/ FallbackInvoke(DynamicMetaObject /*!*/ target, DynamicMetaObject /*!*/[] /*!*/ args,
                                                                   DynamicMetaObject errorSuggestion)
            {
#if !SILVERLIGHT
                DynamicMetaObject result;
                if (Microsoft.Scripting.ComInterop.ComBinder.TryBindInvoke(this, target, InplaceConvertComArguments(args), out result))
                {
                    return(result);
                }
#endif
                return(InvokeMember.FallbackInvokeMember(this, "call", CallInfo, target, args, errorSuggestion, null));
            }
Example #4
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            var model = new InvocationModel()
            {
                Contract   = Contract,
                Method     = binder.Name,
                ReturnType = binder.ReturnType,
                Arguments  = args
            };

            result = InvokeMember.Invoke(model);
            return(true);
        }
Example #5
0
            public override DynamicMetaObject /*!*/ FallbackSetIndex(DynamicMetaObject /*!*/ target, DynamicMetaObject /*!*/[] /*!*/ indexes,
                                                                     DynamicMetaObject /*!*/ value, DynamicMetaObject errorSuggestion)
            {
#if !SILVERLIGHT
                DynamicMetaObject result;
                if (Microsoft.Scripting.ComInterop.ComBinder.TryBindSetIndex(this, target, InplaceConvertComArguments(indexes), ConvertComArgument(value), out result))
                {
                    return(result);
                }
#endif

                return(InvokeMember.FallbackInvokeMember(this, "[]=", CallInfo, target, ArrayUtils.Append(indexes, value), errorSuggestion, null));
            }
Example #6
0
            internal InvokeMember(RubyContext /*!*/ context, string /*!*/ name, CallInfo /*!*/ callInfo, string originalName)
                : base(name, false, callInfo)
            {
                Assert.NotNull(context);
                _context      = context;
                _originalName = originalName;

                if (originalName == null)
                {
                    string unmangled = RubyUtils.TryUnmangleMethodName(Name);
                    if (unmangled != null)
                    {
                        _unmangled = new InvokeMember(_context, unmangled, CallInfo, Name);
                    }
                }
            }
Example #7
0
            internal InvokeMember(RubyContext/*!*/ context, string/*!*/ name, CallInfo/*!*/ callInfo, string originalName)
                : base(name, false, callInfo) {
                Assert.NotNull(context);
                _context = context;
                _originalName = originalName;

                if (originalName == null) {
                    string unmangled = RubyUtils.TryUnmangleMethodName(Name);
                    if (unmangled != null) {
                        _unmangled = new InvokeMember(_context, unmangled, CallInfo, Name);
                    }
                }
            }
Example #8
0
 public override DynamicMetaObject /*!*/ FallbackBinaryOperation(DynamicMetaObject /*!*/ target, DynamicMetaObject /*!*/ arg, DynamicMetaObject errorSuggestion)
 {
     return(InvokeMember.FallbackInvokeMember(this, RubyUtils.MapOperator(Operation), _CallInfo, target, new[] { arg }, errorSuggestion, null));
 }
Example #9
0
 public override DynamicMetaObject /*!*/ FallbackCreateInstance(DynamicMetaObject /*!*/ target, DynamicMetaObject /*!*/[] /*!*/ args,
                                                                DynamicMetaObject errorSuggestion)
 {
     return(InvokeMember.FallbackInvokeMember(this, "new", CallInfo, target, args, errorSuggestion, null));
 }
Example #10
0
            internal static DynamicMetaObject FallbackInvokeMember(IInteropBinder /*!*/ binder, string /*!*/ methodName, CallInfo /*!*/ callInfo,
                                                                   DynamicMetaObject /*!*/ target, DynamicMetaObject /*!*/[] /*!*/ args, DynamicMetaObject errorSuggestion, InvokeMember alternateBinder)
            {
                var metaBuilder = new MetaObjectBuilder(binder, target, args);
                var callArgs    = new CallArguments(binder.Context, target, args, callInfo);

                //
                // If we are called with no errorSuggestion we attempt to bind the alternate name since the current binding failed
                // (unless we successfully bind to a COM object method or Ruby/CLR method defined on the target meta-object).
                // If we already have an errorSuggestion we use it as it represents a valid binding and no alternate name lookups are thus necessary.
                //
                // For example, DynamicObject InvokeMember calls our FallbackInvokeMember 4 times:
                //
                // 1) binder.fallback(..., errorSuggestion: null)
                //    -> DynamicObject.BindInvokeMember(altBinder)
                //       2) altBinder.fallback(..., errorSuggestion: null)
                //          -> [[ error ]]
                //
                //       3) altBinder.fallback(..., errorSuggestion: [[
                //                                                     TryInvokeMember(altName, out result)
                //                                                       ? result
                //                                                       : TryGetMember(altName, out result)
                //                                                           ? altBinder.FallbackInvoke(result)
                //                                                           : [[ error ]]
                //                                                   ]])
                //          -> errorSuggestion
                //
                // 4) binder.fallback(..., errorSuggestion: [[
                //                                            TryInvokeMember(name, out result)
                //                                              ? result
                //                                              : TryGetMember(name, out result)
                //                                                  ? binder.FallbackInvoke(result)
                //                                                    TryInvokeMember(altName, out result)
                //                                                      ? result
                //                                                      : TryGetMember(altName, out result)
                //                                                          ? altBinder.FallbackInvoke(result)
                //                                                          : [[ error ]]
                //
                //                                          ]])
                // -> errorSuggestion
                //
                bool tryAlternateBinding = alternateBinder != null && errorSuggestion == null;

                if (!RubyCallAction.BuildCall(metaBuilder, methodName, callArgs, errorSuggestion == null && !tryAlternateBinding, true))
                {
                    Debug.Assert(errorSuggestion != null || tryAlternateBinding);
                    if (tryAlternateBinding)
                    {
                        metaBuilder.SetMetaResult(target.BindInvokeMember(alternateBinder, args), true);
                    }
                    else
                    {
                        // method wasn't found so we didn't do any operation with arguments that would require restrictions converted to conditions:
                        metaBuilder.SetMetaResult(errorSuggestion, false);
                    }
                }

                return(metaBuilder.CreateMetaObject((DynamicMetaObjectBinder)binder));
            }
Example #11
0
 public override DynamicMetaObject /*!*/ FallbackUnaryOperation(DynamicMetaObject /*!*/ target, DynamicMetaObject errorSuggestion)
 {
     return(InvokeMember.FallbackInvokeMember(this, RubyUtils.MapOperator(Operation), _CallInfo, target, DynamicMetaObject.EmptyMetaObjects, errorSuggestion));
 }