internal IDictionary<object, object> GetAttrDictWithCustomDict(ICallerContext context, ICustomAttributes self, IAttributesDictionary selfDict) { Debug.Assert(IsInstanceOfType(self)); // Get the attributes from the instance Dict res = new Dict(selfDict); // Add the attributes from the type Dict typeDict = base.GetAttrDict(context, self); foreach (KeyValuePair<object, object> pair in (IDictionary<object, object>)typeDict) { res.Add(pair); } return res; }
/// <summary> /// Types implementing ICustomAttributes need special handling for attribute access since they have their own dictionary /// </summary> internal void SetAttrWithCustomDict(ICallerContext context, ICustomAttributes self, IAttributesDictionary selfDict, SymbolId name, object value) { Debug.Assert(IsInstanceOfType(self)); if (name == SymbolTable.Dict) throw Ops.AttributeErrorForReadonlyAttribute(__name__.ToString(), name); object dummy; if (TryLookupSlot(context, name, out dummy)) { SetAttr(context, self, name, value); } else { selfDict[name] = value; } }
internal bool DeleteAttrWithCustomDict(ICallerContext context, ICustomAttributes self, IAttributesDictionary selfDict, SymbolId name) { Debug.Assert(IsInstanceOfType(self)); if (name == SymbolTable.Dict) throw Ops.AttributeErrorForReadonlyAttribute(__name__.ToString(), name); object value; if (selfDict.TryGetValue(name, out value)) { if (value == Uninitialized.instance) return false; selfDict.Remove(name); return true; } object dummy; if (TryLookupSlot(context, name, out dummy)) { selfDict[name] = Uninitialized.instance; return true; } else { return selfDict.Remove(name); } }