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

C# ICallerContext类代码示例

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

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



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

示例1: Call

 public override object Call(ICallerContext context, params object[] args)
 {
     switch (args.Length) {
         case 0: return Call(context);
         default: throw BadArgumentError(args.Length);
     }
 }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:7,代码来源:Function.Generated.cs


示例2: GetAttrNames

        public List GetAttrNames(ICallerContext context)
        {
            LoadAllTypes();

            List res = new List(((IDictionary<object, object>)__dict__).Keys);
            res.Sort();
            return res;
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:8,代码来源:ReflectedPackage.cs


示例3: KwArgBinder

 public KwArgBinder(ICallerContext context, object[] args, string[] keyNames, bool allowUnboundArgs)
 {
     arguments = args;
     kwNames = keyNames;
     Debug.Assert(keyNames.Length <= args.Length);
     fAllowUnboundArgs = allowUnboundArgs;
     ctx = context;
 }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:8,代码来源:kwargbinder.cs


示例4: FindModule

 public static Tuple FindModule(ICallerContext context, string name, List path)
 {
     if (path == null) {
         return FindBuiltinOrSysPath(context, name);
     } else {
         return FindModulePath(context, name, path);
     }
 }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:8,代码来源:imp.cs


示例5: GetAttrNames

        public override List GetAttrNames(ICallerContext context, object self)
        {
            Assembly asm = self as Assembly;
            TopReflectedPackage reflectedAssembly = GetReflectedAssembly(context.SystemState, asm);

            List ret = base.GetAttrNames(context, self);

            ret.AddRange(reflectedAssembly.GetAttrNames(context));
            return ret;
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:10,代码来源:ReflectedAssembly.cs


示例6: TryGetAttr

        public override bool TryGetAttr(ICallerContext context, object self, SymbolId name, out object ret)
        {
            if (base.TryGetAttr(context, self, name, out ret)) {
                return true;
            }

            // This will force creation of the instances dict
            IAttributesDictionary dict = ((ISuperDynamicObject)self).GetDict();
            return dict.TryGetValue(name, out ret);
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:10,代码来源:CompiledType.cs


示例7: Call

        public object Call(ICallerContext context, object[] args, string[] names)
        {
            object targetMethod;
            if (!Ops.GetDynamicType(target).TryLookupBoundSlot(context, target, name, out targetMethod))
                throw Ops.AttributeError("type {0} has no attribute {1}",
                    Ops.GetDynamicType(target.Target),
                    name.ToString());

            return Ops.Call(context, targetMethod, args, names);
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:10,代码来源:_weakref.cs


示例8: GetAttrDict

        public override Dict GetAttrDict(ICallerContext context, object self)
        {
            List attrs = GetAttrNames(context, self);

            Dict res = new Dict();
            foreach (string o in attrs) {
                res[o] = GetAttr(context, self, SymbolTable.StringToId(o));
            }

            return res;
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:11,代码来源:ReflectedAssembly.cs


示例9: SetAttr

        public override void SetAttr(ICallerContext context, object self, SymbolId name, object value)
        {
            object slot;
            bool success = TryGetSlot(context, name, out slot);
            if (success) {
                success = Ops.SetDescriptor(slot, self, value);
            }

            if (!success) {
                // otherwise update the instance
                IAttributesDictionary dict = ((ISuperDynamicObject)self).GetDict();
                dict[name] = value;
            }
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:14,代码来源:CompiledType.cs


示例10: TryGetAttr

        public override bool TryGetAttr(ICallerContext context, object self, SymbolId name, out object ret)
        {
            Assembly asm = self as Assembly;
            TopReflectedPackage reflectedAssembly = GetReflectedAssembly(context.SystemState, asm);

            if (name == SymbolTable.Dict) {
                ret = reflectedAssembly.GetAttrDict(context);
                return true;
            }

            if (base.TryGetAttr(context, self, name, out ret)) {
                return true;
            }

            if (!reflectedAssembly.TryGetAttr(context, name, out ret))
                throw Ops.AttributeError("assembly {0} has no type {1}", asm.GetName().Name, name);

            return true;
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:19,代码来源:ReflectedAssembly.cs


示例11: ReduceProtocol2

        /// <summary>
        /// Implements the default __reduce_ex__ method as specified by PEP 307 case 3 (new-style instance, protocol 2)
        /// </summary>
        private static Tuple ReduceProtocol2(ICallerContext context, object self)
        {
            DynamicType myType = Ops.GetDynamicType(self);

            object func, state, listIterator, dictIterator;
            object[] funcArgs;

            func = PythonCopyReg.PythonNewObject;

            object getNewArgsCallable;
            if (Ops.TryGetAttr(myType, SymbolTable.GetNewArgs, out getNewArgsCallable)) {
                // TypeError will bubble up if __getnewargs__ isn't callable
                Tuple newArgs = Ops.Call(getNewArgsCallable, self) as Tuple;
                if (newArgs == null) {
                    throw Ops.TypeError("__getnewargs__ should return a tuple");
                }
                funcArgs = new object[1 + newArgs.Count];
                funcArgs[0] = myType;
                for (int i = 0; i < newArgs.Count; i++) funcArgs[i + 1] = newArgs[i];
            } else {
                funcArgs = new object[] { myType };
            }

            if (!Ops.TryInvokeSpecialMethod(self, SymbolTable.GetState, out state)) {
                object dict;
                if (!Ops.TryGetAttr(self, SymbolTable.Dict, out dict)) {
                    dict = null;
                }

                Dict initializedSlotValues = GetInitializedSlotValues(self);
                if (initializedSlotValues != null && initializedSlotValues.Count == 0) {
                    initializedSlotValues = null;
                }

                if (dict == null && initializedSlotValues == null) state = null;
                else if (dict != null && initializedSlotValues == null) state = dict;
                else if (dict != null && initializedSlotValues != null) state = Tuple.MakeTuple(dict, initializedSlotValues);
                else   /*dict == null && initializedSlotValues != null*/ state = Tuple.MakeTuple(null, initializedSlotValues);
            }

            listIterator = null;
            if (self is List) {
                listIterator = Ops.GetEnumerator(self);
            }

            dictIterator = null;
            if (self is Dict) {
                dictIterator = Ops.Invoke(self, SymbolTable.IterItems, Ops.EMPTY);
            }

            return Tuple.MakeTuple(func, Tuple.MakeTuple(funcArgs), state, listIterator, dictIterator);
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:55,代码来源:ObjectOps.cs


示例12: Reduce

 public static object Reduce(ICallerContext context, object self)
 {
     return Reduce(context, self, 0);
 }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:4,代码来源:ObjectOps.cs


示例13: SaveReduce

            /// <summary>
            /// Pickle the result of a reduce function.
            /// 
            /// Only context, obj, func, and reduceCallable are required; all other arguments may be null.
            /// </summary>
            private void SaveReduce(ICallerContext context, object obj, object reduceCallable, object func, object args, object state, object listItems, object dictItems)
            {
                if (!Ops.IsCallable(func)) {
                    throw CannotPickle(obj, "func from reduce() should be callable");
                } else if (!(args is Tuple) && args != null) {
                    throw CannotPickle(obj, "args from reduce() should be a tuple");
                } else if (listItems != null && !(listItems is IEnumerator)) {
                    throw CannotPickle(obj, "listitems from reduce() should be a list iterator");
                } else if (dictItems != null && !(dictItems is IEnumerator)) {
                    throw CannotPickle(obj, "dictitems from reduce() should be a dict iterator");
                }

                object funcName;
                string funcNameString;
                if (!Ops.TryGetAttr(func, SymbolTable.Name, out funcName)) {
                    throw CannotPickle(obj, "func from reduce() ({0}) should have a __name__ attribute");
                } else if (!Converter.TryConvertToString(funcName, out funcNameString) || funcNameString == null) {
                    throw CannotPickle(obj, "__name__ of func from reduce() must be string");
                }

                if (protocol >= 2 && "__newobj__" == funcNameString) {
                    if (args == null) {
                        throw CannotPickle(obj, "__newobj__ arglist is None");
                    }
                    Tuple argsTuple = (Tuple)args;
                    if (argsTuple.Count == 0) {
                        throw CannotPickle(obj, "__newobj__ arglist is empty");
                    } else if (!Ops.GetDynamicType(obj).Equals(argsTuple[0])) {
                        throw CannotPickle(obj, "args[0] from __newobj__ args has the wrong class");
                    }
                    Save(context, argsTuple[0]);
                    Save(context, argsTuple[new Slice(1, null)]);
                    Write(Opcode.NewObj);
                } else {
                    Save(context, func);
                    Save(context, args);
                    Write(Opcode.Reduce);
                }

                WritePut(obj);

                if (state != null) {
                    Save(context, state);
                    Write(Opcode.Build);
                }

                if (listItems != null) {
                    BatchAppends(context, (IEnumerator)listItems);
                }

                if (dictItems != null) {
                    BatchSetItems(context, (IEnumerator)dictItems);
                }
            }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:59,代码来源:cPickle.cs


示例14: ReduceProtocol0

        /// <summary>
        /// Implements the default __reduce_ex__ method as specified by PEP 307 case 2 (new-style instance, protocol 0 or 1)
        /// </summary>
        private static Tuple ReduceProtocol0(ICallerContext context, object self)
        {
            // CPython implements this in copy_reg._reduce_ex

            DynamicType myType = Ops.GetDynamicType(self); // PEP 307 calls this "D"
            ThrowIfNativelyPickable(myType);

            object getState;
            bool hasGetState = Ops.TryGetAttr(self, SymbolTable.GetState, out getState);

            object slots;
            if (Ops.TryGetAttr(myType, SymbolTable.Slots, out slots) && Ops.Length(slots) > 0 && !hasGetState) {
                // ??? does this work with superclass slots?
                throw Ops.TypeError("a class that defines __slots__ without defining __getstate__ cannot be pickled with protocols 0 or 1");
            }

            DynamicType closestNonPythonBase = FindClosestNonPythonBase(myType); // PEP 307 calls this "B"

            object func = PythonCopyReg.PythonReconstructor;

            object funcArgs = Tuple.MakeTuple(
                myType,
                closestNonPythonBase,
                TypeCache.Object == closestNonPythonBase ? null : Ops.Call(closestNonPythonBase, self)
            );

            object state;
            if (hasGetState) {
                state = Ops.Call(getState);
            } else {
                Ops.TryGetAttr(self, SymbolTable.Dict, out state);
            }
            if (!Ops.IsTrue(state)) state = null;

            return Tuple.MakeTuple(func, funcArgs, state);
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:39,代码来源:ObjectOps.cs


示例15: SaveDict

            private void SaveDict(ICallerContext context, object obj)
            {
                Debug.Assert(Ops.GetDynamicType(obj).Equals(TypeCache.Dict), "arg must be dict");
                Debug.Assert(!memo.Contains(Ops.Id(obj)));
                Memoize(obj);

                if (protocol < 1) {
                    Write(Opcode.Mark);
                    Write(Opcode.Dict);
                } else {
                    Write(Opcode.EmptyDict);
                }

                WritePut(obj);
                BatchSetItems(context, (DictOps.IterItems((IDictionary<object, object>)obj)));
            }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:16,代码来源:cPickle.cs


示例16: SaveObject

            /// <summary>
            /// Call the appropriate reduce method for obj and pickle the object using
            /// the resulting data. Use the first available of
            /// copy_reg.dispatch_table[type(obj)], obj.__reduce_ex__, and obj.__reduce__.
            /// </summary>
            private void SaveObject(ICallerContext context, object obj)
            {
                Debug.Assert(!memo.Contains(Ops.Id(obj)));
                Memoize(obj);

                object reduceCallable, result;
                DynamicType objType = Ops.GetDynamicType(obj);

                if (PythonCopyReg.DispatchTable.TryGetValue(objType, out reduceCallable)) {
                    result = Ops.Call(reduceCallable, obj);
                } else if (Ops.TryGetAttr(obj, SymbolTable.ReduceEx, out reduceCallable)) {
                    if (obj is DynamicType) {
                        result = Ops.Call(reduceCallable, obj, protocol);
                    } else {
                        result = Ops.Call(reduceCallable, protocol);
                    }
                } else if (Ops.TryGetAttr(obj, SymbolTable.Reduce, out reduceCallable)) {
                    if (obj is DynamicType) {
                        result = Ops.Call(reduceCallable, obj);
                    } else {
                        result = Ops.Call(reduceCallable);
                    }
                } else {
                    throw Ops.AttributeError("no reduce function found for {0}", obj);
                }

                if (objType.Equals(TypeCache.String)) {
                    if (memo.Contains(Ops.Id(obj))) {
                        WriteGet(obj);
                    } else {
                        SaveGlobalByName(context, obj, result);
                    }
                } else if (result is Tuple) {
                    Tuple rt = (Tuple)result;
                    switch (rt.Count) {
                        case 2:
                            SaveReduce(context, obj, reduceCallable, rt[0], rt[1], null, null, null);
                            break;
                        case 3:
                            SaveReduce(context, obj, reduceCallable, rt[0], rt[1], rt[2], null, null);
                            break;
                        case 4:
                            SaveReduce(context, obj, reduceCallable, rt[0], rt[1], rt[2], rt[3], null);
                            break;
                        case 5:
                            SaveReduce(context, obj, reduceCallable, rt[0], rt[1], rt[2], rt[3], rt[4]);
                            break;
                        default:
                            throw CannotPickle(obj, "tuple returned by {0} must have to to five elements", reduceCallable);
                    }
                } else {
                    throw CannotPickle(obj, "{0} must return string or tuple", reduceCallable);
                }
            }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:59,代码来源:cPickle.cs


示例17: SaveList

            private void SaveList(ICallerContext context, object obj)
            {
                Debug.Assert(Ops.GetDynamicType(obj).Equals(TypeCache.List), "arg must be list");
                Debug.Assert(!memo.Contains(Ops.Id(obj)));
                Memoize(obj);
                if (protocol < 1) {
                    Write(Opcode.Mark);
                    Write(Opcode.List);
                } else {
                    Write(Opcode.EmptyList);
                }

                WritePut(obj);
                BatchAppends(context, ((IEnumerable)obj).GetEnumerator());
            }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:15,代码来源:cPickle.cs


示例18: BatchSetItems

            /// <summary>
            /// Emit a series of opcodes that will set all (key, value) pairs indexed by
            /// iter in the object at the top of the stack. Use SETITEMS if possible,
            /// but append no more than BatchSize items at a time.
            /// </summary>
            private void BatchSetItems(ICallerContext context, IEnumerator enumerator)
            {
                Tuple kvTuple;
                if (protocol < 1) {
                    while (enumerator.MoveNext()) {
                        kvTuple = (Tuple)enumerator.Current;
                        Save(context, kvTuple[0]);
                        Save(context, kvTuple[1]);
                        Write(Opcode.SetItem);
                    }
                } else {
                    object nextKey, nextValue;
                    if (enumerator.MoveNext()) {
                        kvTuple = (Tuple)enumerator.Current;
                        nextKey = kvTuple[0];
                        nextValue = kvTuple[1];
                    } else {
                        return;
                    }

                    int batchCompleted = 0;
                    object curKey, curValue;

                    // We do a one-item lookahead to avoid emitting a SETITEMS for a
                    // single remaining item.
                    while (enumerator.MoveNext()) {
                        curKey = nextKey;
                        curValue = nextValue;
                        kvTuple = (Tuple)enumerator.Current;
                        nextKey = kvTuple[0];
                        nextValue = kvTuple[1];

                        if (batchCompleted == BatchSize) {
                            Write(Opcode.SetItems);
                            batchCompleted = 0;
                        }

                        if (batchCompleted == 0) {
                            Write(Opcode.Mark);
                        }

                        Save(context, curKey);
                        Save(context, curValue);
                        batchCompleted++;
                    }

                    if (batchCompleted == BatchSize) {
                        Write(Opcode.SetItems);
                        batchCompleted = 0;
                    }
                    Save(context, nextKey);
                    Save(context, nextValue);
                    batchCompleted++;

                    if (batchCompleted > 1) {
                        Write(Opcode.SetItems);
                    } else {
                        Write(Opcode.SetItem);
                    }
                }
            }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:66,代码来源:cPickle.cs


示例19: SaveInstance

            private void SaveInstance(ICallerContext context, object obj)
            {
                Debug.Assert(Ops.GetDynamicType(obj).Equals(TypeCache.OldInstance), "arg must be old-class instance");
                Debug.Assert(!memo.Contains(Ops.Id(obj)));

                Write(Opcode.Mark);

                // Memoize() call isn't in the usual spot to allow class to be memoized before
                // instance (when using proto other than 0) to match CPython's bytecode output

                object objClass;
                if (!Ops.TryGetAttr(obj, SymbolTable.Class, out objClass)) {
                    throw CannotPickle(obj, "could not determine its __class__");
                }

                if (protocol < 1) {
                    object className, classModuleName;
                    if (!Ops.TryGetAttr(objClass, SymbolTable.Name, out className)) {
                        throw CannotPickle(obj, "its __class__ has no __name__");
                    }
                    classModuleName = FindModuleForGlobal(context, objClass, className);

                    Memoize(obj);
                    WriteInitArgs(context, obj);
                    Write(Opcode.Inst);
                    WriteStringPair(classModuleName, className);
                } else {
                    Save(context, objClass);
                    Memoize(obj);
                    WriteInitArgs(context, obj);
                    Write(Opcode.Obj);
                }

                WritePut(obj);

                object getStateCallable;
                if (Ops.TryGetAttr(obj, SymbolTable.GetState, out getStateCallable)) {
                    Save(context, Ops.Call(getStateCallable));
                } else {
                    Save(context, Ops.GetAttr(context, obj, SymbolTable.Dict));
                }

                Write(Opcode.Build);
            }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:44,代码来源:cPickle.cs


示例20: SaveInteger

 private void SaveInteger(ICallerContext context, object obj)
 {
     Debug.Assert(Ops.GetDynamicType(obj).Equals(TypeCache.Int32), "arg must be int");
     if (protocol < 1) {
         Write(Opcode.Int);
         WriteIntAsString(obj);
     } else {
         if (IsUInt8(obj)) {
             Write(Opcode.BinInt1);
             WriteUInt8(obj);
         } else if (IsUInt16(obj)) {
             Write(Opcode.BinInt2);
             WriteUInt16(obj);
         } else if (IsInt32(obj)) {
             Write(Opcode.BinInt);
             WriteInt32(obj);
         } else {
             throw Ops.RuntimeError("unrecognized integer format");
         }
     }
 }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:21,代码来源:cPickle.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# ICamera类代码示例发布时间:2022-05-24
下一篇:
C# ICallableType类代码示例发布时间: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