本文整理汇总了C#中ICallerContext类的典型用法代码示例。如果您正苦于以下问题:C# ICallerContext类的具体用法?C# ICallerContext怎么用?C# ICallerContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ICallerContext类属于命名空间,在下文中一共展示了ICallerContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例2: GetAttrNames
public List GetAttrNames(ICallerContext context)
{
LoadAllTypes();
List res = new List(((IDictionary<object, object>)__dict__).Keys);
res.Sort();
return res;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
示例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);
}
示例12: Reduce
public static object Reduce(ICallerContext context, object self)
{
return Reduce(context, self, 0);
}
示例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);
}
}
示例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);
}
示例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)));
}