本文整理汇总了C#中IronPython.Runtime.Types.PythonType.TryResolveSlot方法的典型用法代码示例。如果您正苦于以下问题:C# PythonType.TryResolveSlot方法的具体用法?C# PythonType.TryResolveSlot怎么用?C# PythonType.TryResolveSlot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IronPython.Runtime.Types.PythonType
的用法示例。
在下文中一共展示了PythonType.TryResolveSlot方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTypeNew
private static object GetTypeNew(CodeContext/*!*/ context, PythonType dt) {
PythonTypeSlot dts;
if (!dt.TryResolveSlot(context, "__new__", out dts)) {
throw PythonOps.TypeError("cannot create instances of {0}", dt.Name);
}
object newInst;
bool res = dts.TryGetValue(context, dt, dt, out newInst);
Debug.Assert(res);
return newInst;
}
示例2: TryGetGetAttribute
/// <summary>
/// Checks to see if this type has __getattribute__ that overrides all other attribute lookup.
///
/// This is more complex then it needs to be. The problem is that when we have a
/// mixed new-style/old-style class we have a weird __getattribute__ defined. When
/// we always dispatch through rules instead of PythonTypes it should be easy to remove
/// this.
/// </summary>
private static bool TryGetGetAttribute(CodeContext/*!*/ context, PythonType/*!*/ type, out PythonTypeSlot dts) {
if (type.TryResolveSlot(context, Symbols.GetAttribute, out dts)) {
BuiltinMethodDescriptor bmd = dts as BuiltinMethodDescriptor;
if (bmd == null || bmd.DeclaringType != typeof(object) ||
bmd.Template.Targets.Count != 1 ||
bmd.Template.Targets[0].DeclaringType != typeof(ObjectOps) ||
bmd.Template.Targets[0].Name != "__getattribute__") {
return dts != null;
}
}
return false;
}
示例3: AddFinalizer
private static void AddFinalizer(CodeContext/*!*/ context, PythonType dt, object newObject) {
// check if object has finalizer...
PythonTypeSlot dummy;
if (dt.TryResolveSlot(context, "__del__", out dummy)) {
IWeakReferenceable iwr = newObject as IWeakReferenceable;
Debug.Assert(iwr != null);
InstanceFinalizer nif = new InstanceFinalizer(context, newObject);
iwr.SetFinalizer(new WeakRefTracker(nif, nif));
}
}