/// <summary> /// Object.ToString() displays the CLI type name. But we want to display the class name (e.g. /// '<foo object at 0x000000000000002C>' unless we've overridden __repr__ but not __str__ in /// which case we'll display the result of __repr__. /// </summary> public static string ToStringHelper(ISuperDynamicObject o) { object ret; UserType ut = o.GetDynamicType() as UserType; if (ut.TryLookupSlot(DefaultContext.Default, SymbolTable.Repr, out ret)) { return(Converter.ConvertToString(Ops.Call(Ops.GetDescriptor(ret, o, ut)))); } return(PythonType.ReprMethod(o).ToString()); }
public static object DelAttrMethod(object self, object name) { string strName = name as string; if (strName == null) { throw Ops.TypeError("attribute name must be a string"); } ISuperDynamicObject s = self as ISuperDynamicObject; if (s == null) { throw new NotImplementedException(); } ((UserType)s.GetDynamicType()).DelAttr(DefaultContext.Default, s, SymbolTable.StringToId(strName)); return(null); }
public static object GetAttributeMethod(object self, object name) { string strName = name as string; if (strName == null) { throw Ops.TypeError("attribute name must be a string"); } ISuperDynamicObject s = self as ISuperDynamicObject; if (s != null) { object ret; if (((UserType)s.GetDynamicType()).TryBaseGetAttr(DefaultContext.Default, s, SymbolTable.StringToId(strName), out ret)) { return(ret); } } throw Ops.AttributeError("no attribute {0}", name); //??? better message }
/// <summary> /// Object.ToString() displays the CLI type name. But we want to display the class name (e.g. /// '<foo object at 0x000000000000002C>' unless we've overridden __repr__ but not __str__ in /// which case we'll display the result of __repr__. /// </summary> public static string ToStringHelper(ISuperDynamicObject o) { object ret; UserType ut = o.GetDynamicType() as UserType; if (ut.TryLookupBoundSlot(DefaultContext.Default, o, SymbolTable.Repr, out ret)) { string strRet; if (ret != null && Converter.TryConvertToString(Ops.Call(Ops.GetDescriptor(ret, o, ut)), out strRet)) return strRet; throw Ops.TypeError("__repr__ returned non-string type ({0})", Ops.GetDynamicType(ret).__name__); } return DynamicType.ReprMethod(o).ToString(); }