PythonTypeFromDictProxy(DictProxy proxy) { FieldInfo _typeField = (FieldInfo)(proxy.GetType().GetMember( "_dt", BindingFlags.NonPublic | BindingFlags.Instance)[0]); return((PythonType)_typeField.GetValue(proxy)); }
PyDict_Size(IntPtr dictPtr) { IDictionary dict = (IDictionary)this.Retrieve(dictPtr); if (dict is DictProxy) { DictProxy proxy = (DictProxy)dict; return(proxy.__len__(this.scratchContext)); } return(dict.Keys.Count); }
private void EnsureAll() { if (!_gotAll) { HashSet <string> result = new HashSet <string>(); if (_objects.Length == 1 && (_objects[0] is PythonType)) { // fast path for when we're looking up in a type, this is about twice as fast // as going through the normal code path. PythonType pyType = (PythonType)_objects[0]; foreach (var baseType in pyType.mro()) { PythonType curType = (baseType as PythonType); if (curType != null) { var dict = new DictProxy(curType); var enumerator = dict.iteritems(_showClr ? _projectState.CodeContextCls : _projectState.CodeContext); while (enumerator.MoveNext()) { PythonTuple value = (PythonTuple)enumerator.Current; string key = (string)value[0]; if (_variables.ContainsKey(key)) { continue; } _variables[key] = _projectState.GetNamespaceFromObjects(value[1]).SelfSet; } } } } else { foreach (var module in _objects) { foreach (var name in Utils.DirHelper(module, _showClr)) { GetClr(name, _showClr, null); } } } _gotAll = true; } }
private object GetOne(string index, bool showClr) { if (IsVisible(index, showClr)) { PythonType pyType = (_obj as PythonType); if (pyType != null) { foreach (var baseType in pyType.mro()) { PythonType curType = (baseType as PythonType); if (curType != null) { IDictionary <object, object> dict = new DictProxy(curType); object bresult; if (dict.TryGetValue(index, out bresult)) { return(bresult); } } } } var tracker = _obj as NamespaceTracker; if (tracker != null) { object value = NamespaceTrackerOps.GetCustomMember(_interpreter.CodeContext, tracker, index); if (value != OperationFailed.Value) { return(value); } else { return(this); } } object result; if (_interpreter.TryGetMember(_obj, index, showClr, out result)) { return(result); } } return(this); // sentinel indicating failure }
internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value) { if (instance == null) { value = new DictProxy(owner); return true; } PythonType pt = instance as PythonType; if (pt != null) { value = new DictProxy(pt); return true; } IPythonObject sdo = instance as IPythonObject; if (sdo != null) { IAttributesCollection res = sdo.Dict; if (res != null || (res = sdo.SetDict(PythonDictionary.MakeSymbolDictionary())) != null) { value = res; return true; } } value = null; return false; }
public static PythonType PythonTypeFromDictProxy(DictProxy proxy) { FieldInfo _typeField = (FieldInfo)(proxy.GetType().GetMember( "_dt", BindingFlags.NonPublic | BindingFlags.Instance)[0]); return (PythonType)_typeField.GetValue(proxy); }