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

C# Runtime.CodeContext类代码示例

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

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



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

示例1: __new__

        public static object __new__(CodeContext/*!*/ context, PythonType cls, object x) {
            if (cls == TypeCache.Double) {
                if (x is string) {
                    return ParseFloat((string)x);
                } else if (x is Extensible<string>) {
                    object res;
                    if (PythonTypeOps.TryInvokeUnaryOperator(context, x, Symbols.ConvertToFloat, out res)) {
                        return res;
                    }
                    return ParseFloat(((Extensible<string>)x).Value);
                } else if (x is char) {
                    return ParseFloat(ScriptingRuntimeHelpers.CharToString((char)x));
                }

                double doubleVal;
                if (Converter.TryConvertToDouble(x, out doubleVal)) return doubleVal;

                if (x is Complex64) throw PythonOps.TypeError("can't convert complex to float; use abs(z)");

                object d = PythonOps.CallWithContext(context, PythonOps.GetBoundAttr(context, x, Symbols.ConvertToFloat));
                if (d is double) return d;
                throw PythonOps.TypeError("__float__ returned non-float (type %s)", DynamicHelpers.GetPythonType(d));
            } else {
                return cls.CreateInstance(context, x);
            }
        }
开发者ID:techarch,项目名称:ironruby,代码行数:26,代码来源:FloatOps.cs


示例2: DynamicStackFrame

 public DynamicStackFrame(CodeContext context, MethodBase method, string funcName, string filename, int line) {
     _context = context;
     _funcName = funcName;
     _filename = filename;
     _lineNo = line;
     _method = method;
 }
开发者ID:joshholmes,项目名称:ironruby,代码行数:7,代码来源:DynamicStackFrame.cs


示例3: __new__

        public static object __new__(CodeContext context, PythonType cls, object x) {
            Extensible<string> es;

            if (x is string) {
                return ReturnBigInteger(context, cls, ParseBigIntegerSign((string)x, 10));
            } else if ((es = x as Extensible<string>) != null) {
                object value;
                if (PythonTypeOps.TryInvokeUnaryOperator(context, x, Symbols.ConvertToLong, out value)) {
                    return ReturnBigInteger(context, cls, (BigInteger)value);
                }

                return ReturnBigInteger(context, cls, ParseBigIntegerSign(es.Value, 10));
            }

            BigInteger intVal;
            if (Converter.TryConvertToBigInteger(x, out intVal)) {
                if (Object.Equals(intVal, null)) throw PythonOps.TypeError("can't convert {0} to long", PythonTypeOps.GetName(x));

                return ReturnBigInteger(context, cls, intVal);
            }


            if (x is Complex64) throw PythonOps.TypeError("can't convert complex to long; use long(abs(z))");

            throw PythonOps.ValueError("long argument must be convertible to long (string, number, or type that defines __long__, got {0})",
                StringOps.Quote(PythonOps.GetPythonTypeName(x)));
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:27,代码来源:LongOps.cs


示例4: CodeContext

        public CodeContext(Scope scope, LanguageContext languageContext, CodeContext parent) {
            Assert.NotNull(languageContext);

            _languageContext = languageContext;
            _scope = scope;
            _parent = parent;
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:7,代码来源:CodeContext.cs


示例5: TrySetValue

 internal override bool TrySetValue(CodeContext context, object instance, PythonType owner, object value) {
     IWeakReferenceable reference;
     if (context.GetPythonContext().TryConvertToWeakReferenceable(instance, out reference)) {
         return reference.SetWeakRef(new WeakRefTracker(value, instance));
     }
     return false;
 }
开发者ID:paweljasinski,项目名称:ironpython3,代码行数:7,代码来源:PythonTypeWeakRefSlot.cs


示例6: __new__

        public static object __new__(CodeContext/*!*/ context, PythonType cls, object x) {
            if (cls == TypeCache.Double) {
                if (x is string) {
                    return ParseFloat((string)x);
                } else if (x is Extensible<string>) {
                    object res;
                    if (PythonTypeOps.TryInvokeUnaryOperator(context, x, "__float__", out res)) {
                        return res;
                    }
                    return ParseFloat(((Extensible<string>)x).Value);
                } else if (x is char) {
                    return ParseFloat(ScriptingRuntimeHelpers.CharToString((char)x));
                }

                if (x is Complex) {
                    throw PythonOps.TypeError("can't convert complex to float; use abs(z)");
                }

                object d = PythonOps.CallWithContext(context, PythonOps.GetBoundAttr(context, x, "__float__"));
                if (d is double) {
                    return d;
                } else if (d is Extensible<double>) {
                    return ((Extensible<double>)d).Value;
                }

                throw PythonOps.TypeError("__float__ returned non-float (type {0})", PythonTypeOps.GetName(d));
            } else {
                return cls.CreateInstance(context, x);
            }
        }
开发者ID:follesoe,项目名称:ironruby,代码行数:30,代码来源:FloatOps.cs


示例7: TrySetValue

 internal override bool TrySetValue(CodeContext context, object instance, PythonType owner, object value) {
     IWeakReferenceable reference = instance as IWeakReferenceable;
     if (reference != null) {
         return reference.SetWeakRef(new WeakRefTracker(value, instance));
     }
     return false;
 }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:7,代码来源:PythonTypeWeakRefSlot.cs


示例8: TryDeleteValue

        internal override bool TryDeleteValue(CodeContext context, object instance, PythonType owner) {
            if (_deleter == null || instance == null) {
                return base.TryDeleteValue(context, instance, owner);
            }

            CallTarget(context, null, new MethodInfo[] { _deleter }, instance);
            return true;
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:8,代码来源:ReflectedExtensionProperty.cs


示例9: TrySetValue

        internal override bool TrySetValue(CodeContext context, object instance, PythonType owner, object value) {
            if (instance != null) {
                Setter(instance, value);
                return true;
            }

            return false;
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:8,代码来源:ReflectedSlotProperty.cs


示例10: TryGetValue

 internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value) {
     try {
         value = PythonOps.GetUserDescriptor(Value, instance, owner);
         return true;
     } catch (MissingMemberException) {
         value = null;
         return false;
     }
 }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:9,代码来源:PythonTypeUserDescriptorSlot.cs


示例11: TryGetValue

        internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value) {
            if (Getter.Length == 0 || instance == null) {
                value = null;
                return false;
            }

            value = CallGetter(context, null, instance, ArrayUtils.EmptyObjects);
            return true;
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:9,代码来源:ReflectedExtensionProperty.cs


示例12: TryGetValue

        internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value) {
            if (Getter.Length == 0 || (instance == null && Getter[0].IsDefined(typeof(WrapperDescriptorAttribute), false))) {
                value = null;
                return false;
            }

            value = CallGetter(context, null, instance, ArrayUtils.EmptyObjects);
            return true;
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:9,代码来源:ReflectedExtensionProperty.cs


示例13: __new__

        public static object __new__(CodeContext context, PythonType cls, object x) {
            Extensible<string> es;

            if (x is string) {
                return ReturnObject(context, cls, ParseBigIntegerSign((string)x, 10));
            } else if ((es = x as Extensible<string>) != null) {
                object value;
                if (PythonTypeOps.TryInvokeUnaryOperator(context, x, "__long__", out value)) {
                    return ReturnObject(context, cls, (BigInteger)value);
                }

                return ReturnObject(context, cls, ParseBigIntegerSign(es.Value, 10));
            }
            if (x is double) return ReturnObject(context, cls, DoubleOps.__long__((double)x));
            if (x is int) return ReturnObject(context, cls, (BigInteger)(int)x);
            if (x is BigInteger) return ReturnObject(context, cls, x);
            
            if (x is Complex) throw PythonOps.TypeError("can't convert complex to long; use long(abs(z))");

            if (x is decimal) {
                return ReturnObject(context, cls, (BigInteger)(decimal)x);
            }

            object result;
            int intRes;
            BigInteger bigintRes;
            if (PythonTypeOps.TryInvokeUnaryOperator(context, x, "__long__", out result) &&
                !Object.ReferenceEquals(result, NotImplementedType.Value) ||
                x is OldInstance &&
                PythonTypeOps.TryInvokeUnaryOperator(context, x, "__int__", out result) &&
                !Object.ReferenceEquals(result, NotImplementedType.Value)) {
                if (result is int || result is BigInteger ||
                    result is Extensible<int> || result is Extensible<BigInteger>) {
                    return ReturnObject(context, cls, result);
                } else {
                    throw PythonOps.TypeError("__long__ returned non-long (type {0})", PythonTypeOps.GetOldName(result));
                }
            } else if (PythonOps.TryGetBoundAttr(context, x, "__trunc__", out result)) {
                result = PythonOps.CallWithContext(context, result);
                if (Converter.TryConvertToInt32(result, out intRes)) {
                    return ReturnObject(context, cls, (BigInteger)intRes);
                } else if (Converter.TryConvertToBigInteger(result, out bigintRes)) {
                    return ReturnObject(context, cls, bigintRes);
                } else {
                    throw PythonOps.TypeError("__trunc__ returned non-Integral (type {0})", PythonTypeOps.GetOldName(result));
                }
            }

            if (x is OldInstance) {
                throw PythonOps.AttributeError("{0} instance has no attribute '__trunc__'",
                    ((OldInstance)x)._class.Name);
            } else {
                throw PythonOps.TypeError("long() argument must be a string or a number, not '{0}'",
                    DynamicHelpers.GetPythonType(x).Name);
            }
        }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:56,代码来源:LongOps.cs


示例14: MakeIsCallableRule

        // This can produce a IsCallable rule that returns the immutable constant isCallable.
        // Beware that objects can have a mutable callable property. Eg, in Python, assign or delete the __call__ attribute.
        public static bool MakeIsCallableRule(CodeContext context, object self, bool isCallable, RuleBuilder rule) {
            rule.MakeTest(CompilerHelpers.GetType(self));
            rule.Target =
                rule.MakeReturn(
                    context.LanguageContext.Binder,
                    Ast.Constant(isCallable)
                );

            return true;
        }
开发者ID:bclubb,项目名称:ironruby,代码行数:12,代码来源:BinderHelper.cs


示例15: TryGetValue

        internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value) {
            if (instance != null) {
                value = Getter(instance);
                PythonOps.CheckInitializedAttribute(value, instance, _name);
                return true;
            }

            value = this;
            return true;
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:10,代码来源:ReflectedSlotProperty.cs


示例16: __new__

        public static object __new__(CodeContext context, PythonType pythonType, ICollection items) {
            Type type = pythonType.UnderlyingSystemType.GetElementType();

            Array res = Array.CreateInstance(type, items.Count);

            int i = 0;
            foreach (object item in items) {
                res.SetValue(Converter.Convert(item, type), i++);
            }

            return res;
        }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:12,代码来源:ArrayOps.cs


示例17: GetMemberNames

        public static List GetMemberNames(CodeContext/*!*/ context, Assembly self) {
            Debug.Assert(self != null);
            List ret = DynamicHelpers.GetPythonTypeFromType(self.GetType()).GetMemberNames(context);

            foreach (object o in GetReflectedAssembly(context, self).Keys) {
                if (o is string) {
                    ret.AddNoLock((string)o);
                }
            }

            return ret;
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:12,代码来源:PythonAssemblyOps.cs


示例18: TryGetValue

        internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value) {
            if (instance == null) {
                if (owner == TypeCache.Null) {
                    value = owner;
                } else {
                    value = DynamicHelpers.GetPythonType(owner);
                }
            } else {
                value = DynamicHelpers.GetPythonType(instance);
            }

            return true;
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:13,代码来源:PythonTypeTypeSlot.cs


示例19: CreateInstance

        internal override object CreateInstance(CodeContext context) {
            if (_ctorSite0 == null) {
                Interlocked.CompareExchange(
                    ref _ctorSite0,
                    CallSite<Func<CallSite, CodeContext, BuiltinFunction, PythonType, object>>.Create(
                        PythonContext.GetContext(context).DefaultBinderState.InvokeOne
                    ),
                    null
                );
            }

            return _ctorSite0.Target(_ctorSite0, context, Type.Ctor, Type);
        }
开发者ID:tnachen,项目名称:ironruby,代码行数:13,代码来源:InstanceCreator.cs


示例20: GetReflectedAssembly

        private static TopNamespaceTracker GetReflectedAssembly(CodeContext/*!*/ context, Assembly assem) {
            Debug.Assert(assem != null);
            lock (assemblyMap) {
                TopNamespaceTracker reflectedAssembly;
                if (assemblyMap.TryGetValue(assem, out reflectedAssembly))
                    return reflectedAssembly;

                reflectedAssembly = new TopNamespaceTracker(context.LanguageContext.DomainManager);
                reflectedAssembly.LoadAssembly(assem);
                assemblyMap[assem] = reflectedAssembly;

                return reflectedAssembly;
            }
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:14,代码来源:PythonAssemblyOps.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Harness.LogMessage类代码示例发布时间:2022-05-26
下一篇:
C# Math.Complex64类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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