当前位置: 首页>>代码示例>>C#>>正文


C# Dynamic.DynamicMetaObjectBinder类代码示例

本文整理汇总了C#中System.Dynamic.DynamicMetaObjectBinder的典型用法代码示例。如果您正苦于以下问题:C# DynamicMetaObjectBinder类的具体用法?C# DynamicMetaObjectBinder怎么用?C# DynamicMetaObjectBinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DynamicMetaObjectBinder类属于System.Dynamic命名空间,在下文中一共展示了DynamicMetaObjectBinder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TypeError

        /*!*/
        public static DynamicMetaObject TypeError(DynamicMetaObjectBinder/*!*/ action, string message, params DynamicMetaObject[] types)
        {
            if (action is ITotemSite)
            {
                ITotemSite site = (ITotemSite)action;

                message = String.Format(message, ArrayUtils.ConvertAll(types, x => {
                    var t = site.Context.GetTypeHandler(x.LimitType);
                    if (t != null)
                        return t.Name;

                    return x.LimitType.Name;
                }));

                Expression error = action.Throw(
                    Ast.Call(
                        AstMethods.SimpleTypeError,
                        Ast.Constant(message)
                    ),
                    typeof(object)
                );

                return new DynamicMetaObject(
                    error,
                    BindingRestrictions.Combine(types)
                );
            }

            return GenericFallback(action, types);
        }
开发者ID:Alxandr,项目名称:IronTotem,代码行数:31,代码来源:TotemProtocol.cs

示例2: ConvertToString

        internal static DynamicMetaObject ConvertToString(DynamicMetaObjectBinder conversion, DynamicMetaObject self)
        {
            Assert.NotNull(conversion, self);

            TotemType ltype = MetaTotemObject.GetTotemType(self);
            var matches = ltype.GetOperatorFunctions(TotemOperationKind.ToString).ToList();

            var overloadResolver = GetTotemContext(conversion).SharedOverloadResolverFactory.CreateOverloadResolver(new[] { self }, new CallSignature(1), CallTypes.None);
            var ret = overloadResolver.ResolveOverload("ToString", ArrayUtils.ToArray(matches, m => CreateOverloadInfo(m)), NarrowingLevel.None, NarrowingLevel.All);

            if (!ret.Success)
            {
                return new DynamicMetaObject(
                    Expression.Throw(
                        Expression.Call(
                            AstMethods.TypeError,
                            Utils.Constant("No toString found on type {1}."),
                            Expression.NewArrayInit(
                                typeof(string),
                                Expression.Constant(ltype.Name)
                            )
                        )
                    ),
                    BindingRestrictions.Combine(new[] { self })
                );
            }
            return new DynamicMetaObject(ret.MakeExpression(), ret.RestrictedArguments.GetAllRestrictions());
        }
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:28,代码来源:TotemProtocol.cs

示例3: CreateMetaObject

        internal DynamicMetaObject/*!*/ CreateMetaObject(DynamicMetaObjectBinder/*!*/ action) {
            Debug.Assert(ControlFlowBuilder == null, "Control flow required but not built");

            var expr = _error ? Ast.Throw(_result) : _result;

            if (_condition != null) {
                var deferral = action.GetUpdateExpression(typeof(object));
                expr = Ast.Condition(_condition, AstUtils.Convert(expr, typeof(object)), deferral);
            }

            if (_temps != null) {
                expr = Ast.Block(_temps, expr);
            }

#if DEBUG && !SILVERLIGHT && !SYSTEM_CORE
            if (RubyOptions.ShowRules) {
                var oldColor = Console.ForegroundColor;
                try {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("Rule #{0}: {1}", Interlocked.Increment(ref _ruleCounter), action);
                    Console.ForegroundColor = ConsoleColor.DarkGray;
                    var d = (_restrictions != BindingRestrictions.Empty) ? Ast.IfThen(_restrictions.ToExpression(), expr) : expr;
                    d.DumpExpression(null, Console.Out);
                } finally {
                    Console.ForegroundColor = oldColor;
                }
            }
#endif

            return new DynamicMetaObject(expr, _restrictions);
        }
开发者ID:toddb,项目名称:ironruby,代码行数:31,代码来源:MetaObjectBuilder.cs

示例4: CSharpBinder

		public CSharpBinder (DynamicMetaObjectBinder binder, Compiler.Expression expr, DynamicMetaObject errorSuggestion)
		{
			this.binder = binder;
			this.expr = expr;
			this.restrictions = BindingRestrictions.Empty;
			this.errorSuggestion = errorSuggestion;
		}
开发者ID:bbqchickenrobot,项目名称:playscript-mono,代码行数:7,代码来源:CSharpBinder.cs

示例5: Bind

            public static DynamicMetaObject/*!*/ Bind(string/*!*/ methodName, CallInfo/*!*/ callInfo,
                DynamicMetaObjectBinder/*!*/ binder, DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args,
                Func<DynamicMetaObject, DynamicMetaObject[], DynamicMetaObject>/*!*/ fallback)
            {
                Debug.Assert(fallback != null);

                //create DMO
                var phpInvokeBinder = Binder.MethodCall(methodName, 0, callInfo.ArgumentCount, null, Types.Object[0]) as PhpBaseInvokeMemberBinder;

                if (phpInvokeBinder != null)
                {

                    //Add ScriptContext.CurrentContext
                    var context = new DynamicMetaObject(Expression.Call(Methods.ScriptContext.GetCurrentContext), BindingRestrictions.Empty);

                    var restrictions = BinderHelper.GetSimpleInvokeRestrictions(target, args);

                    //Value type arguments have to be boxed
                    DynamicMetaObject[] arguments = new DynamicMetaObject[1 + args.Length];
                    arguments[0] = context;
                    for (int i = 0; i < args.Length; ++i)
                        arguments[1 + i] = new DynamicMetaObject(WrapDynamic(args[i].Expression),
                                                                 args[i].Restrictions);
                    var result = phpInvokeBinder.Bind(target, arguments);

                    //Unwrap result
                    var res = new DynamicMetaObject(Unwrap(result.Expression), restrictions);

                    return res;
                }
                else
                    return fallback(target, args);//this will never happen
            }
开发者ID:dw4dev,项目名称:Phalanger,代码行数:33,代码来源:InteropBinder.cs

示例6: WeavingContext

 /// <summary>
 /// Constror 
 /// </summary>
 /// <param name="target">Be weaved object.</param>
 /// <param name="binder">Dynamic object binder <see cref="DynamicMetaObjectBinder"/></param>
 /// <param name="argumentValues">To store Arguement values of calling method.</param>
 /// <param name="returnValue">To store  return value of the calling method, if it has one.</param>
 public WeavingContext(object target, DynamicMetaObjectBinder binder, object[] argumentValues=null, object returnValue=null)
 {
     this.Target = target;
     this.binder = binder;
     this.ArgumentValues = argumentValues;
     this.ReturnValue = returnValue;
 }
开发者ID:bzure,项目名称:BCF,代码行数:14,代码来源:WeavingContext.cs

示例7: Call

        internal static DynamicMetaObject Call(DynamicMetaObjectBinder call, DynamicMetaObject target, DynamicMetaObject[] args)
        {
            Assert.NotNull(call, args);
            Assert.NotNullItems(args);

            if (target.NeedsDeferral())
                return call.Defer(ArrayUtils.Insert(target, args));

            foreach (var mo in args)
            {
                if (mo.NeedsDeferral())
                {
                    RestrictTypes(args);

                    return call.Defer(
                        ArrayUtils.Insert(target, args)
                    );
                }
            }

            DynamicMetaObject self = target.Restrict(target.GetLimitType());

            ValidationInfo valInfo = BindingHelpers.GetValidationInfo(target);
            TotemType tt = DynamicHelpers.GetTotemType(target.Value);
            TotemContext toContext = GetTotemContext(call);

            throw new NotImplementedException();
        }
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:28,代码来源:TotemProtocol.cs

示例8: IsNoThrow

        internal static bool IsNoThrow(DynamicMetaObjectBinder action) {
            PythonGetMemberBinder gmb = action as PythonGetMemberBinder;
            if (gmb != null) {
                return gmb.IsNoThrow;
            }

            return false;
        }
开发者ID:jschementi,项目名称:iron,代码行数:8,代码来源:BindingHelpers.cs

示例9: FallbackConvert

        public DynamicMetaObject FallbackConvert(DynamicMetaObjectBinder binder)
        {
            TotemConversionBinder toBinder = binder as TotemConversionBinder;
            if (toBinder != null)
                return toBinder.FallbackConvert(binder.ReturnType, this, null);

            return ((ConvertBinder)binder).FallbackConvert(this);
        }
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:8,代码来源:MetaTotemObject.cs

示例10: FallbackConvert

        public DynamicMetaObject/*!*/ FallbackConvert(DynamicMetaObjectBinder/*!*/ binder) {
            PythonConversionBinder pyBinder = binder as PythonConversionBinder;
            if (pyBinder != null) {
                return pyBinder.FallbackConvert(binder.ReturnType, this, null);
            }

            return ((ConvertBinder)binder).FallbackConvert(this);
        }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:8,代码来源:MetaPythonObject.cs

示例11: GetBinderState

        public static BinderState/*!*/ GetBinderState(DynamicMetaObjectBinder/*!*/ action) {
            IPythonSite pySite = action as IPythonSite;
            if (pySite != null) {
                return pySite.Binder;
            }

            Debug.Assert(Default != null);
            return Default;
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:9,代码来源:BinderState.cs

示例12: GetOptionalVersionAndLanguageCheckForType

 internal static BindingRestrictions GetOptionalVersionAndLanguageCheckForType(DynamicMetaObjectBinder binder, Type targetType, int expectedVersionNumber)
 {
     BindingRestrictions empty = BindingRestrictions.Empty;
     if (CoreTypes.Contains(targetType))
     {
         return empty;
     }
     if (expectedVersionNumber != -1)
     {
         empty = empty.Merge(GetVersionCheck(binder, expectedVersionNumber));
     }
     return empty.Merge(GetLanguageModeCheckIfHasEverUsedConstrainedLanguage());
 }
开发者ID:nickchal,项目名称:pash,代码行数:13,代码来源:BinderUtils.cs

示例13: BinaryRetTypeBinder

 public BinaryRetTypeBinder(DynamicMetaObjectBinder operationBinder, PythonConversionBinder conversionBinder) :
     base(new BinderMappingInfo(
             operationBinder,
             ParameterMappingInfo.Parameter(0),
             ParameterMappingInfo.Parameter(1)
         ),
         new BinderMappingInfo(
             conversionBinder,
             ParameterMappingInfo.Action(0)
         )
     ) {
     _opBinder = operationBinder;
     _convBinder = conversionBinder;
 }
开发者ID:andreakn,项目名称:ironruby,代码行数:14,代码来源:BinaryRetTypeBinder.cs

示例14: InvokeWorker

        private DynamicMetaObject/*!*/ InvokeWorker(DynamicMetaObjectBinder/*!*/ call, Expression/*!*/ codeContext, DynamicMetaObject/*!*/[]/*!*/ args) {
            if (this.NeedsDeferral()) {
                return call.Defer(ArrayUtils.Insert(this, args));
            }

            for (int i = 0; i < args.Length; i++) {
                if (args[i].NeedsDeferral()) {
                    return call.Defer(ArrayUtils.Insert(this, args));
                }
            }

            if (Value.IsUnbound) {
                return MakeSelflessCall(call, codeContext, args);
            } else {
                return MakeSelfCall(call, codeContext, args);
            }
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:17,代码来源:MetaBuiltinFunction.cs

示例15: InvokeWorker

        private DynamicMetaObject/*!*/ InvokeWorker(DynamicMetaObjectBinder/*!*/ call, Expression/*!*/ codeContext, DynamicMetaObject/*!*/[] args) {
            CallSignature signature = BindingHelpers.GetCallSignature(call);
            BindingRestrictions selfRestrict = BindingRestrictions.GetInstanceRestriction(Expression, Value).Merge(Restrictions);

            selfRestrict = selfRestrict.Merge(
                BindingRestrictions.GetExpressionRestriction(
                    MakeFunctionTest(
                        Ast.Call(
                            typeof(PythonOps).GetMethod("GetBuiltinMethodDescriptorTemplate"),
                            Ast.Convert(Expression, typeof(BuiltinMethodDescriptor))
                        )
                    )
                )
            );

            return Value.Template.MakeBuiltinFunctionCall(
                call,
                codeContext,
                this,
                args,
                false,  // no self
                true,
                selfRestrict,
                (newArgs) => {
                    BindingTarget target;

                    BinderState state = BinderState.GetBinderState(call);

                    DynamicMetaObject res = state.Binder.CallMethod(
                        new ParameterBinderWithCodeContext(state.Binder, codeContext),
                        Value.Template.Targets,
                        newArgs,
                        signature,
                        selfRestrict,
                        NarrowingLevel.None,
                        Value.Template.IsBinaryOperator ?
                            PythonNarrowing.BinaryOperator :
                            NarrowingLevel.All,
                        Value.Template.Name,
                        out target
                    );

                    return new BuiltinFunction.BindingResult(target, res);
                });            
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:45,代码来源:MetaBuiltinMethodDescriptor.cs


注:本文中的System.Dynamic.DynamicMetaObjectBinder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。