static PropertyDescriptor[] GetPropertiesImpl(object self, Attribute[] attributes) { IList <object> attrNames = PythonOps.GetAttrNames(DefaultContext.DefaultCLS, self); List <PropertyDescriptor> descrs = new List <PropertyDescriptor>(); if (attrNames != null) { foreach (object o in attrNames) { string s = o as string; if (s == null) { continue; } PythonTypeSlot attrSlot; PythonType dt = DynamicHelpers.GetPythonType(self); dt.TryResolveSlot(DefaultContext.DefaultCLS, s, out attrSlot); object attrVal = ObjectOps.__getattribute__(DefaultContext.DefaultCLS, self, s); Type attrType = (attrVal == null) ? typeof(NoneTypeOps) : attrVal.GetType(); if ((attrSlot != null && ShouldIncludeProperty(attrSlot, attributes)) || (attrSlot == null && ShouldIncludeInstanceMember(s, attributes))) { descrs.Add(new SuperDynamicObjectPropertyDescriptor(s, attrType, self.GetType())); } } } return(descrs.ToArray()); }
static PropertyDescriptor[] GetPropertiesImpl(object self, Attribute[] attributes) { IList <object> attrNames = PythonOps.GetAttrNames(DefaultContext.DefaultCLS, self); List <PropertyDescriptor> descrs = new List <PropertyDescriptor>(); if (attrNames != null) { foreach (object o in attrNames) { if (!(o is string s)) { continue; } PythonTypeSlot attrSlot = null; object attrVal; if (self is OldInstance) { if (((OldInstance)self)._class.TryLookupSlot(s, out attrVal)) { attrSlot = attrVal as PythonTypeSlot; } else if (!((OldInstance)self).Dictionary.TryGetValue(s, out attrVal)) { attrVal = ObjectOps.__getattribute__(DefaultContext.DefaultCLS, self, s); } } else { PythonType dt = DynamicHelpers.GetPythonType(self); dt.TryResolveSlot(DefaultContext.DefaultCLS, s, out attrSlot); attrVal = ObjectOps.__getattribute__(DefaultContext.DefaultCLS, self, s); } Type attrType = (attrVal == null) ? typeof(NoneTypeOps) : attrVal.GetType(); if ((attrSlot != null && ShouldIncludeProperty(attrSlot, attributes)) || (attrSlot == null && ShouldIncludeInstanceMember(s, attributes))) { descrs.Add(new SuperDynamicObjectPropertyDescriptor(s, attrType, self.GetType())); } } } return(descrs.ToArray()); }
/// <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(IPythonObject o) { return(ObjectOps.__str__(DefaultContext.Default, o)); }
public static string __format__(CodeContext /*!*/ context, Complex self, string formatSpec) { // TODO: this is not correct, but it's better than the .ToString representation return(ObjectOps.__format__(context, self, formatSpec)); }