public object values(CodeContext context) { List res = new List(); foreach (KeyValuePair <object, object> kvp in _dt.GetMemberDictionary(context, false)) { PythonTypeUserDescriptorSlot dts = kvp.Value as PythonTypeUserDescriptorSlot; if (dts != null) { res.AddNoLock(dts.Value); } else { res.AddNoLock(kvp.Value); } } return(res); }
private object GetIndex(CodeContext context, object index) { string strIndex = index as string; if (strIndex != null) { PythonTypeSlot dts; if (_dt.TryLookupSlot(context, strIndex, out dts)) { PythonTypeUserDescriptorSlot uds = dts as PythonTypeUserDescriptorSlot; if (uds != null) { return(uds.Value); } return(dts); } } throw PythonOps.KeyError(index.ToString()); }
public List items(CodeContext context) { List res = new List(); foreach (KeyValuePair <object, object> kvp in _dt.GetMemberDictionary(context, false)) { PythonTypeUserDescriptorSlot dts = kvp.Value as PythonTypeUserDescriptorSlot; object val; if (dts != null) { val = dts.Value; } else { val = kvp.Value; } res.append(PythonTuple.MakeTuple(kvp.Key, val)); } return(res); }
private bool TryGetValue(CodeContext /*!*/ context, object key, out object value) { string strIndex = key as string; if (strIndex != null) { PythonTypeSlot dts; if (_dt.TryLookupSlot(context, strIndex, out dts)) { PythonTypeUserDescriptorSlot uds = dts as PythonTypeUserDescriptorSlot; if (uds != null) { value = uds.Value; return(true); } value = dts; return(true); } } value = null; return(false); }
internal static PythonTypeSlot GetReflectedField(FieldInfo info) { PythonTypeSlot res; NameType nt = NameType.Field; if (!PythonBinder.IsExtendedType(info.DeclaringType) && !info.IsDefined(typeof(PythonHiddenAttribute), false)) { nt |= NameType.PythonField; } lock (_fieldCache) { if (!_fieldCache.TryGetValue(info, out res)) { if (nt == NameType.PythonField && info.IsLiteral) { if (info.FieldType == typeof(int)) { res = new PythonTypeUserDescriptorSlot( ScriptingRuntimeHelpers.Int32ToObject((int)info.GetRawConstantValue()), true ); } else if (info.FieldType == typeof(bool)) { res = new PythonTypeUserDescriptorSlot( ScriptingRuntimeHelpers.BooleanToObject((bool)info.GetRawConstantValue()), true ); } else { res = new PythonTypeUserDescriptorSlot( info.GetValue(null), true ); } } else { res = new ReflectedField(info, nt); } _fieldCache[info] = res; } } return res; }
private void PopulateSlot(SymbolId key, object value) { PythonTypeSlot pts = value as PythonTypeSlot; if (pts == null) { pts = new PythonTypeUserDescriptorSlot(value); } AddSlot(key, pts); }
internal void SetCustomMember(CodeContext/*!*/ context, SymbolId name, object value) { Debug.Assert(context != null); PythonTypeSlot dts; if (TryResolveSlot(context, name, out dts)) { if (dts.TrySetValue(context, null, this, value)) return; } if (PythonType._pythonTypeType.TryResolveSlot(context, name, out dts)) { if (dts.TrySetValue(context, this, PythonType._pythonTypeType, value)) return; } if (IsSystemType) { throw new MissingMemberException(String.Format("'{0}' object has no attribute '{1}'", Name, SymbolTable.IdToString(name))); } dts = value as PythonTypeSlot; if (dts != null) { _dict[name] = dts; } else if (IsSystemType) { _dict[name] = new PythonTypeValueSlot(value); } else { _dict[name] = new PythonTypeUserDescriptorSlot(value); } UpdateVersion(); }
/// <summary> /// Searches the resolution order for a slot matching by name. /// /// Includes searching for methods in old-style classes /// </summary> internal bool TryResolveMixedSlot(CodeContext context, SymbolId name, out PythonTypeSlot slot) { for (int i = 0; i < _resolutionOrder.Count; i++) { PythonType dt = _resolutionOrder[i]; if (dt.TryLookupSlot(context, name, out slot)) { return true; } if (dt.OldClass != null) { object ret; if (dt.OldClass.TryLookupSlot(name, out ret)) { slot = ret as PythonTypeSlot; if (slot == null) { slot = new PythonTypeUserDescriptorSlot(ret); } return true; } } } slot = null; return false; }