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


C# DynamicMetaObjectBinder.Throw方法代码示例

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


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

示例1: TypeError

        /// <summary>
        /// Produces an error message for the provided message and type names.  The error message should contain
        /// string formatting characters ({0}, {1}, etc...) for each of the type names.
        /// </summary>
        public static DynamicMetaObject/*!*/ TypeError(DynamicMetaObjectBinder/*!*/ action, string message, params DynamicMetaObject[] types) {
            if (action is IPythonSite) {
                message = String.Format(message, ArrayUtils.ConvertAll(types, x => MetaPythonObject.GetPythonType(x).Name));

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

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

            return GenericFallback(action, types);
        }
开发者ID:jdhardy,项目名称:ironpython,代码行数:24,代码来源:PythonProtocol.Operations.cs

示例2: CompleteRuleTarget

            public override DynamicMetaObject/*!*/ CompleteRuleTarget(DynamicMetaObjectBinder/*!*/ metaBinder, DynamicMetaObject/*!*/[]/*!*/ args, Func<DynamicMetaObject> customFailure) {
                ConditionalBuilder cb = new ConditionalBuilder();
                _slot.MakeGetExpression(
                    Binder,
                    AstUtils.Constant(PythonContext.SharedContext),
                    args[0],
                    new DynamicMetaObject(
                        Ast.Call(
                            typeof(DynamicHelpers).GetMethod("GetPythonType"),
                            AstUtils.Convert(args[0].Expression, typeof(object))
                        ),
                        BindingRestrictions.Empty,
                        DynamicHelpers.GetPythonType(args[0].Value)
                    ),
                    cb
                );
                if (!cb.IsFinal) {
                    cb.FinishCondition(metaBinder.Throw(Ast.New(typeof(InvalidOperationException))));
                }

                Expression callable = cb.GetMetaObject().Expression;
                Expression[] exprArgs = new Expression[args.Length - 1];
                for (int i = 1; i < args.Length; i++) {
                    exprArgs[i - 1] = args[i].Expression;
                }

                Expression retVal = DynamicExpression.Dynamic(
                    PythonContext.Invoke(
                        new CallSignature(exprArgs.Length)
                    ),
                    typeof(object),
                    ArrayUtils.Insert(AstUtils.Constant(PythonContext.SharedContext), (Expression)callable, exprArgs)
                );

                if (IsSetter) {
                    retVal = Ast.Block(retVal, args[args.Length - 1].Expression);
                }

                return new DynamicMetaObject(
                    retVal,
                    BindingRestrictions.Combine(args)
                );
            }
开发者ID:jdhardy,项目名称:ironpython,代码行数:43,代码来源:PythonProtocol.Operations.cs

示例3: MakeBinaryThrow

        private static DynamicMetaObject/*!*/ MakeBinaryThrow(DynamicMetaObjectBinder/*!*/ action, PythonOperationKind op, DynamicMetaObject/*!*/[]/*!*/ args) {
            if (action is IPythonSite) {
                // produce the custom Python error message
                return new DynamicMetaObject(
                    action.Throw(
                        Ast.Call(
                            typeof(PythonOps).GetMethod("TypeErrorForBinaryOp"),
                            AstUtils.Constant(Symbols.OperatorToSymbol(NormalizeOperator(op))),
                            AstUtils.Convert(args[0].Expression, typeof(object)),
                            AstUtils.Convert(args[1].Expression, typeof(object))
                        ),
                        typeof(object)
                    ),
                    BindingRestrictions.Combine(args)
                );
            }

            // let the site produce its own error
            return GenericFallback(action, args);
        }
开发者ID:jdhardy,项目名称:ironpython,代码行数:20,代码来源:PythonProtocol.Operations.cs

示例4: MakeGenericTypeDefinitionError

        private DynamicMetaObject/*!*/ MakeGenericTypeDefinitionError(DynamicMetaObjectBinder/*!*/ call, ArgumentValues/*!*/ ai, ValidationInfo/*!*/ valInfo) {
            Debug.Assert(Value.IsSystemType);
            string message = "cannot create instances of " + Value.Name + " because it is a generic type definition";

            return BindingHelpers.AddDynamicTestAndDefer(
                call,
                new DynamicMetaObject(
                    call.Throw(
                        Ast.New(
                            typeof(TypeErrorException).GetConstructor(new Type[] { typeof(string) }),
                            AstUtils.Constant(message)
                        ),
                        typeof(object)
                    ),
                    GetErrorRestrictions(ai)
                ),
                ai.Arguments,
                valInfo
            );
        }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:20,代码来源:MetaPythonType.Calls.cs

示例5: TypeError

        public static DynamicMetaObject TypeError(DynamicMetaObjectBinder action, string message, params DynamicMetaObject[] types)
        {
            if (action is ITotemSite)
            {
                message = string.Format(message, ArrayUtils.ConvertAll(types, x => MetaTotemObject.GetTotemType(x).Name));

                Expression error = action.Throw(
                    Expression.Call(
                        typeof(TotemOps).GetMethod("SimpleTypeError"),
                        Expression.Constant(message)
                    ),
                    typeof(object)
                );

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

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

示例6: MakeIncorrectArgumentsForCallError

        private DynamicMetaObject/*!*/ MakeIncorrectArgumentsForCallError(DynamicMetaObjectBinder/*!*/ call, ArgumentValues/*!*/ ai, ValidationInfo/*!*/ valInfo) {
            string message;

            if (Value.IsSystemType) {
                if (Value.UnderlyingSystemType.GetConstructors().Length == 0) {
                    // this is a type we can't create ANY instances of, give the user a half-way decent error message
                    message = "cannot create instances of " + Value.Name;
                } else {
                    message = InstanceOps.ObjectNewNoParameters;
                }
            } else {
                message = InstanceOps.ObjectNewNoParameters;
            }

            return BindingHelpers.AddDynamicTestAndDefer(
                call,
                new DynamicMetaObject(
                    call.Throw(
                        Ast.New(
                            typeof(TypeErrorException).GetConstructor(new Type[] { typeof(string) }),
                            AstUtils.Constant(message)
                        )
                    ),
                    GetErrorRestrictions(ai)
                ), 
                ai.Arguments,                
                valInfo
            );
        }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:29,代码来源:MetaPythonType.Calls.cs

示例7: MakeStandardDotNetTypeCall

        /// <summary>
        /// Creating a standard .NET type is easy - we just call it's constructor with the provided
        /// arguments.
        /// </summary>
        private DynamicMetaObject/*!*/ MakeStandardDotNetTypeCall(DynamicMetaObjectBinder/*!*/ call, Expression/*!*/ codeContext, DynamicMetaObject/*!*/[]/*!*/ args) {
            CallSignature signature = BindingHelpers.GetCallSignature(call);
            PythonContext state = PythonContext.GetPythonContext(call);
            MethodBase[] ctors = CompilerHelpers.GetConstructors(Value.UnderlyingSystemType, state.Binder.PrivateBinding);

            if (ctors.Length > 0) {
                return state.Binder.CallMethod(
                    new PythonOverloadResolver(
                        state.Binder,
                        args,
                        signature,
                        codeContext
                    ),
                    ctors,
                    Restrictions.Merge(BindingRestrictions.GetInstanceRestriction(Expression, Value))
                );
            } else {
                string msg;
                if (Value.UnderlyingSystemType.IsAbstract()) {
                    msg = String.Format("Cannot create instances of {0} because it is abstract", Value.Name);
                }else{
                    msg = String.Format("Cannot create instances of {0} because it has no public constructors", Value.Name);
                }
                return new DynamicMetaObject(
                   call.Throw(
                       Ast.New(
                           typeof(TypeErrorException).GetConstructor(new Type[] { typeof(string) }),
                           AstUtils.Constant(msg)
                       )
                   ),
                   Restrictions.Merge(BindingRestrictions.GetInstanceRestriction(Expression, Value))
                );
            }
        }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:38,代码来源:MetaPythonType.Calls.cs

示例8: FallbackGet

        private Expression FallbackGet(DynamicMetaObjectBinder member, DynamicMetaObject[] args) {
            GetMemberBinder sa = member as GetMemberBinder;
            if (sa != null) {
                return sa.FallbackGetMember(args[0]).Expression;
            }

            PythonGetMemberBinder pyGetMem = member as PythonGetMemberBinder;
            if (pyGetMem.IsNoThrow) {
                return Ast.Field(
                    null,
                    typeof(OperationFailed).GetDeclaredField("Value")
                );
            } else {
                return member.Throw(
                    Ast.Call(
                        typeof(PythonOps).GetMethod("AttributeError"),
                        AstUtils.Constant("{0} instance has no attribute '{1}'"),
                        Ast.NewArrayInit(
                            typeof(object),
                            AstUtils.Constant(((OldInstance)Value)._class._name),
                            AstUtils.Constant(pyGetMem.Name)
                        )
                    )
                );
            }
        }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:26,代码来源:MetaOldInstance.cs

示例9: IncorrectArgCount

 private static DynamicMetaObject IncorrectArgCount(DynamicMetaObjectBinder binder, BindingRestrictions restrictions, int expected, int got) {
     return new DynamicMetaObject(
         binder.Throw(
             Expression.Call(
                 typeof(PythonOps).GetMethod("TypeError"),
                 Expression.Constant(String.Format("this function takes {0} arguments ({1} given)", expected, got)),
                 Expression.NewArrayInit(typeof(object))                                    
             ),
             typeof(object)
         ),
         restrictions
     );
 }
开发者ID:jschementi,项目名称:iron,代码行数:13,代码来源:CFuncPtr.cs

示例10: NoThisParam

 private static DynamicMetaObject NoThisParam(DynamicMetaObjectBinder binder, BindingRestrictions restrictions) {
     return new DynamicMetaObject(
         binder.Throw(
             Expression.Call(
                 typeof(PythonOps).GetMethod("ValueError"),
                 Expression.Constant("native com method call without 'this' parameter"),
                 Expression.NewArrayInit(typeof(object))
             ),
             typeof(object)
         ),
         restrictions
     );
 }
开发者ID:TerabyteX,项目名称:ironpython3,代码行数:13,代码来源:CFuncPtr.cs


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