Exemple #1
0
        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;
            }
        }
Exemple #2
0
        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
        }