• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# PythonContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Convert

 /// <summary>
 /// Backwards compatible Convert for the old sites that need to flow CodeContext
 /// </summary>
 public static Expression/*!*/ Convert(Expression/*!*/ codeContext, PythonContext/*!*/ binder, Type/*!*/ type, ConversionResultKind resultKind, Expression/*!*/ target) {
     return Ast.Dynamic(
         binder.Convert(type, resultKind),
         type,
         target
     );
 }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:10,代码来源:Binders.cs


示例2: Get

 public static Expression/*!*/ Get(Expression/*!*/ codeContext, PythonContext/*!*/ binder, Type/*!*/ resultType, string/*!*/ name, Expression/*!*/ target) {
     return Ast.Dynamic(
         binder.GetMember(name),
         resultType,
         target,
         codeContext
     );
 }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:8,代码来源:Binders.cs


示例3: ShouldWarn

        public static bool ShouldWarn(PythonContext/*!*/ context, MethodBase/*!*/ method, out WarningInfo info) {
            Assert.NotNull(method);

            ObsoleteAttribute[] os = (ObsoleteAttribute[])method.GetCustomAttributes(typeof(ObsoleteAttribute), true);
            if (os.Length > 0) {
                info = new WarningInfo(
                    PythonExceptions.DeprecationWarning,
                    String.Format("{0}.{1} has been obsoleted.  {2}",
                        NameConverter.GetTypeName(method.DeclaringType),
                        method.Name,
                        os[0].Message
                    )
                );

                return true;
            }

            if (context.PythonOptions.WarnPython30) {
                Python3WarningAttribute[] py3kwarnings = (Python3WarningAttribute[])method.GetCustomAttributes(typeof(Python3WarningAttribute), true);
                if (py3kwarnings.Length > 0) {
                    info = new WarningInfo(
                        PythonExceptions.DeprecationWarning,
                        py3kwarnings[0].Message
                    );

                    return true;
                }
            }

#if !SILVERLIGHT
            // no apartment states on Silverlight
            if (method.DeclaringType == typeof(Thread)) {
                if (method.Name == "Sleep") {
                    info = new WarningInfo(
                        PythonExceptions.RuntimeWarning,
                        "Calling Thread.Sleep on an STA thread doesn't pump messages.  Use Thread.CurrentThread.Join instead.",
                        Expression.Equal(
                            Expression.Call(
                                Expression.Property(
                                    null,
                                    typeof(Thread).GetProperty("CurrentThread")
                                ),
                                typeof(Thread).GetMethod("GetApartmentState")
                            ),
                            AstUtils.Constant(ApartmentState.STA)
                        ),
                        () => Thread.CurrentThread.GetApartmentState() == ApartmentState.STA
                    );

                    return true;
                }
            }
#endif

            info = null;
            return false;
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:57,代码来源:BindingWarnings.cs


示例4: BinaryOperationBinder

        public static DynamicMetaObjectBinder BinaryOperationBinder(PythonContext state, PythonOperationKind operatorName) {
            ExpressionType? et = GetExpressionTypeFromBinaryOperator(operatorName);

            if (et == null) {
                return state.Operation(
                    operatorName
                );
            }

            return state.BinaryOperation(et.Value);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:11,代码来源:Binders.cs


示例5: MakeTryGetTypeMember

 internal static MethodCallExpression MakeTryGetTypeMember(PythonContext/*!*/ PythonContext, PythonTypeSlot dts, ParameterExpression tmp, Expression instance, Expression pythonType) {
     return Ast.Call(
         PythonTypeInfo._PythonOps.SlotTryGetBoundValue,
         AstUtils.Constant(PythonContext.SharedContext),
         AstUtils.Convert(Utils.WeakConstant(dts), typeof(PythonTypeSlot)),
         AstUtils.Convert(instance, typeof(object)),
         AstUtils.Convert(
             pythonType,
             typeof(PythonType)
         ),
         tmp
     );
 }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:13,代码来源:MetaPythonObject.cs


示例6: TryGetStaticFunction

 /// <summary>
 /// Tries to get the BuiltinFunction for the given name on the type of the provided MetaObject.  
 /// 
 /// Succeeds if the MetaObject is a BuiltinFunction or BuiltinMethodDescriptor.
 /// </summary>
 internal static bool TryGetStaticFunction(PythonContext/*!*/ state, string op, DynamicMetaObject/*!*/ mo, out BuiltinFunction function) {
     PythonType type = MetaPythonObject.GetPythonType(mo);
     function = null;
     if (!String.IsNullOrEmpty(op)) {
         PythonTypeSlot xSlot;
         object val;
         if (type.TryResolveSlot(state.SharedContext, op, out xSlot) &&
             xSlot.TryGetValue(state.SharedContext, null, type, out val)) {
             function = TryConvertToBuiltinFunction(val);
             if (function == null) return false;
         }
     }
     return true;
 }
开发者ID:jschementi,项目名称:iron,代码行数:19,代码来源:BindingHelpers.cs


示例7: PythonBinder

        public PythonBinder(ScriptDomainManager manager, PythonContext/*!*/ pythonContext, CodeContext context)
            : base(manager) {
            ContractUtils.RequiresNotNull(pythonContext, "pythonContext");

            _context = pythonContext;
            if (context != null) {
                context.LanguageContext.DomainManager.AssemblyLoaded += new EventHandler<AssemblyLoadedEventArgs>(DomainManager_AssemblyLoaded);

                foreach (Assembly asm in pythonContext.DomainManager.GetLoadedAssemblyList()) {
                    DomainManager_AssemblyLoaded(this, new AssemblyLoadedEventArgs(asm));
                }
            }

            EmptyGetMemberAction = OldGetMemberAction.Make(this, String.Empty);
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:15,代码来源:PythonBinder.cs


示例8: SlotCallable

 public SlotCallable(PythonContext/*!*/ binder, PythonIndexType op, PythonTypeSlot slot)
     : base(binder, op) {
     _slot = slot;
 }
开发者ID:jdhardy,项目名称:ironpython,代码行数:4,代码来源:PythonProtocol.Operations.cs


示例9: BuiltinCallable

            public BuiltinCallable(PythonContext/*!*/ binder, PythonIndexType op, BuiltinFunction/*!*/ func)
                : base(binder, op) {
                Assert.NotNull(func);

                _bf = func;
            }
开发者ID:jdhardy,项目名称:ironpython,代码行数:6,代码来源:PythonProtocol.Operations.cs


示例10: MakeCallable

            /// <summary>
            /// Creates a new CallableObject.  If BuiltinFunction is available we'll create a BuiltinCallable otherwise
            /// we create a SlotCallable.
            /// </summary>
            public static Callable MakeCallable(PythonContext/*!*/ binder, PythonIndexType op, BuiltinFunction itemFunc, PythonTypeSlot itemSlot) {
                if (itemFunc != null) {
                    // we'll call a builtin function to produce the rule
                    return new BuiltinCallable(binder, op, itemFunc);
                } else if (itemSlot != null) {
                    // we'll call a PythonTypeSlot to produce the rule
                    return new SlotCallable(binder, op, itemSlot);
                }

                return null;
            }
开发者ID:jdhardy,项目名称:ironpython,代码行数:15,代码来源:PythonProtocol.Operations.cs


示例11: Callable

            protected Callable(PythonContext/*!*/ binder, PythonIndexType op) {
                Assert.NotNull(binder);

                _binder = binder;
                _op = op;
            }
开发者ID:jdhardy,项目名称:ironpython,代码行数:6,代码来源:PythonProtocol.Operations.cs


示例12: MakeOneTarget

        private static bool MakeOneTarget(PythonContext/*!*/ state, SlotOrFunction/*!*/ target, PythonTypeSlot slotTarget, ConditionalBuilder/*!*/ bodyBuilder, bool reverse, DynamicMetaObject/*!*/[]/*!*/ types) {
            if (target == SlotOrFunction.Empty && slotTarget == null) return true;

            if (slotTarget != null) {
                MakeSlotCall(state, types, bodyBuilder, slotTarget, reverse);
                return true;
            } else if (target.MaybeNotImplemented) {
                Debug.Assert(target.ReturnType == typeof(object));

                ParameterExpression tmp = Ast.Variable(typeof(object), "slot");
                bodyBuilder.AddVariable(tmp);

                bodyBuilder.AddCondition(
                    Ast.NotEqual(
                        Ast.Assign(
                            tmp,
                            target.Target.Expression
                        ),
                        Ast.Property(null, typeof(PythonOps).GetProperty("NotImplemented"))
                    ),
                    tmp
                );

                return true;
            } else {
                bodyBuilder.FinishCondition(target.Target.Expression, typeof(object));
                return false;
            }
        }
开发者ID:jdhardy,项目名称:ironpython,代码行数:29,代码来源:PythonProtocol.Operations.cs


示例13: HashConvertToInt

 private static DynamicExpression/*!*/ HashConvertToInt(PythonContext/*!*/ state, Expression/*!*/ expression) {
     return DynamicExpression.Dynamic(
         state.Convert(
             typeof(int),
             ConversionResultKind.ExplicitCast
         ),
         typeof(int),
         expression
     );
 }
开发者ID:jdhardy,项目名称:ironpython,代码行数:10,代码来源:PythonProtocol.Operations.cs


示例14: GetGetOrDeleteSlice

        private static DynamicMetaObject/*!*/ GetGetOrDeleteSlice(PythonContext state, DynamicMetaObject/*!*/[]/*!*/ args) {
            DynamicMetaObject[] newArgs = (DynamicMetaObject[])args.Clone();
            for (int i = 1; i < newArgs.Length; i++) {
                if (!IsIndexType(state, newArgs[i])) {
                    newArgs[i] = newArgs[i].Restrict(newArgs[i].GetLimitType());
                }
            }

            return new DynamicMetaObject(
                Ast.Call(
                    typeof(PythonOps).GetMethod("MakeSlice"),
                    AstUtils.Convert(GetGetOrDeleteParameter(newArgs, 1), typeof(object)),
                    AstUtils.Convert(GetGetOrDeleteParameter(newArgs, 2), typeof(object)),
                    AstUtils.Convert(GetGetOrDeleteParameter(newArgs, 3), typeof(object))
                ),
                BindingRestrictions.Combine(newArgs)
            );
        }
开发者ID:jdhardy,项目名称:ironpython,代码行数:18,代码来源:PythonProtocol.Operations.cs


示例15: MakeRule

            public override DynamicMetaObject/*!*/ MakeRule(DynamicMetaObjectBinder/*!*/ metaBinder, PythonContext/*!*/ binder, DynamicMetaObject/*!*/[]/*!*/ args) {
                DynamicMetaObject[] tupleArgs = Callable.GetTupleArguments(args);
                return Callable.CompleteRuleTarget(metaBinder, tupleArgs, delegate() {
                    PythonTypeSlot indexSlot;
                    if (args[1].GetLimitType() != typeof(Slice) && GetTypeAt(1).TryResolveSlot(binder.SharedContext, "__index__", out indexSlot)) {
                        args[1] = new DynamicMetaObject(
                            DynamicExpression.Dynamic(
                                binder.Convert(
                                    typeof(int),
                                    ConversionResultKind.ExplicitCast
                                ),
                                typeof(int),
                                DynamicExpression.Dynamic(
                                    binder.InvokeNone,
                                    typeof(object),
                                    AstUtils.Constant(binder.SharedContext),
                                    Binders.Get(
                                        AstUtils.Constant(binder.SharedContext),
                                        binder,
                                        typeof(object),
                                        "__index__",
                                        args[1].Expression
                                    )
                                )
                            ),
                            BindingRestrictions.Empty
                        );

                        return Callable.CompleteRuleTarget(metaBinder, tupleArgs, null);
                    }
                    return null;
                });
            }
开发者ID:jdhardy,项目名称:ironpython,代码行数:33,代码来源:PythonProtocol.Operations.cs


示例16: InvokeKeywords

 /// <summary>
 /// Creates a new InvokeBinder which will call with positional and keyword splatting.
 /// 
 /// The signature of the target site should be object(function), object[], dictionary, retType
 /// </summary>
 public static PythonInvokeBinder/*!*/ InvokeKeywords(PythonContext/*!*/ state) {
     return state.Invoke(
         new CallSignature(new Argument(ArgumentType.List), new Argument(ArgumentType.Dictionary))
     );
 }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:10,代码来源:Binders.cs


示例17: InvokeSplat

 /// <summary>
 /// Creates a new InvokeBinder which will call with positional splatting.
 /// 
 /// The signature of the target site should be object(function), object[], retType
 /// </summary>
 /// <param name="state"></param>
 /// <returns></returns>
 public static PythonInvokeBinder/*!*/ InvokeSplat(PythonContext/*!*/ state) {
     return state.Invoke(
         new CallSignature(new Argument(ArgumentType.List))
     );
 }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:12,代码来源:Binders.cs


示例18: LoadScriptCode

        private static void LoadScriptCode(PythonContext/*!*/ pc, Assembly/*!*/ asm) {
            ScriptCode[] codes = ScriptCode.LoadFromAssembly(pc.DomainManager, asm);

            foreach (ScriptCode sc in codes) {
                pc.GetCompiledLoader().AddScriptCode(sc);
            }
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:7,代码来源:PythonBinder.cs


示例19: MakeSlotCallWorker

        private static void MakeSlotCallWorker(PythonContext/*!*/ state, PythonTypeSlot/*!*/ slotTarget, Expression/*!*/ self, ConditionalBuilder/*!*/ bodyBuilder, params Expression/*!*/[]/*!*/ args) {
            // Generate:
            // 
            // SlotTryGetValue(context, slot, selfType, out callable) && (tmp=callable(args)) != NotImplemented) ?
            //      tmp :
            //      RestOfOperation
            //
            ParameterExpression callable = Ast.Variable(typeof(object), "slot");
            ParameterExpression tmp = Ast.Variable(typeof(object), "slot");

            bodyBuilder.AddCondition(
                Ast.AndAlso(
                    Ast.Call(
                        typeof(PythonOps).GetMethod("SlotTryGetValue"),
                        AstUtils.Constant(state.SharedContext),
                        AstUtils.Convert(Utils.WeakConstant(slotTarget), typeof(PythonTypeSlot)),
                        AstUtils.Convert(self, typeof(object)),
                        Ast.Call(
                            typeof(DynamicHelpers).GetMethod("GetPythonType"),
                            AstUtils.Convert(self, typeof(object))
                        ),
                        callable
                    ),
                    Ast.NotEqual(
                        Ast.Assign(
                            tmp,
                            DynamicExpression.Dynamic(
                                state.Invoke(
                                    new CallSignature(args.Length)
                                ),
                                typeof(object),
                                ArrayUtils.Insert(AstUtils.Constant(state.SharedContext), (Expression)callable, args)
                            )
                        ),
                        Ast.Property(null, typeof(PythonOps).GetProperty("NotImplemented"))
                    )
                ),
                tmp
            );
            bodyBuilder.AddVariable(callable);
            bodyBuilder.AddVariable(tmp);
        }
开发者ID:jdhardy,项目名称:ironpython,代码行数:42,代码来源:PythonProtocol.Operations.cs


示例20: IsIndexType

        private static bool IsIndexType(PythonContext/*!*/ state, DynamicMetaObject/*!*/ obj) {
            bool numeric = true;
            if (obj.GetLimitType() != typeof(MissingParameter) &&
                !PythonOps.IsNumericType(obj.GetLimitType())) {

                PythonType curType = MetaPythonObject.GetPythonType(obj);
                PythonTypeSlot dummy;

                if (!curType.TryResolveSlot(state.SharedContext, "__index__", out dummy)) {
                    numeric = false;
                }
            }
            return numeric;
        }
开发者ID:jdhardy,项目名称:ironpython,代码行数:14,代码来源:PythonProtocol.Operations.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# PythonDictionary类代码示例发布时间:2022-05-24
下一篇:
C# PyObject类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap