Esempio n. 1
0
        public AnalysisValue GetAnalysisValueFromObjects(object attr)
        {
            if (attr == null)
            {
                return(_noneInst);
            }

            var attrType = attr.GetType();

            if (attr is IPythonType pt)
            {
                return(GetBuiltinType(pt));
            }
            else if (attr is IPythonFunction pf)
            {
                return(GetCached(attr, () => new BuiltinFunctionInfo(pf, this)) ?? _noneInst);
            }
            else if (attr is IPythonMethodDescriptor md)
            {
                return(GetCached(attr, () => {
                    if (md.IsBound)
                    {
                        return new BuiltinFunctionInfo(md.Function, this);
                    }
                    else
                    {
                        return new BuiltinMethodInfo(md, this);
                    }
                }) ?? _noneInst);
            }
            else if (attr is IPythonBoundFunction pbf)
            {
                return(GetCached(attr, () => new BoundBuiltinMethodInfo(pbf, this)) ?? _noneInst);
            }
            else if (attr is IBuiltinProperty bp)
            {
                return(GetCached(attr, () => new BuiltinPropertyInfo(bp, this)) ?? _noneInst);
            }
            else if (attr is IPythonModule pm)
            {
                return(_modules.GetBuiltinModule(pm));
            }
            else if (attr is IPythonEvent pe)
            {
                return(GetCached(attr, () => new BuiltinEventInfo(pe, this)) ?? _noneInst);
            }
            else if (attr is IPythonConstant ||
                     attrType == typeof(bool) || attrType == typeof(int) || attrType == typeof(Complex) ||
                     attrType == typeof(string) || attrType == typeof(long) || attrType == typeof(double))
            {
                return(GetConstant(attr).First());
            }
            else if (attr is IMemberContainer mc)
            {
                return(GetCached(attr, () => new ReflectedNamespace(mc, this)));
            }
            else if (attr is IPythonMultipleMembers mm)
            {
                var members = mm.Members;
                return(GetCached(attr, () =>
                                 MultipleMemberInfo.Create(members.Select(GetAnalysisValueFromObjects)).FirstOrDefault() ??
                                 ClassInfos[BuiltinTypeId.NoneType].Instance
                                 ));
            }
            else
            {
                var pyAttrType = GetTypeFromObject(attr);
                Debug.Assert(pyAttrType != null);
                return(GetBuiltinType(pyAttrType).Instance);
            }
        }
Esempio n. 2
0
        internal AnalysisValue GetAnalysisValueFromObjects(object attr)
        {
            if (attr == null)
            {
                return(_noneInst);
            }

            var attrType = (attr != null) ? attr.GetType() : typeof(NoneType);

            if (attr is IPythonType)
            {
                return(GetBuiltinType((IPythonType)attr));
            }
            else if (attr is IPythonFunction)
            {
                var bf = (IPythonFunction)attr;
                return(GetCached(attr, () => new BuiltinFunctionInfo(bf, this)) ?? _noneInst);
            }
            else if (attr is IPythonMethodDescriptor)
            {
                return(GetCached(attr, () => {
                    var md = (IPythonMethodDescriptor)attr;
                    if (md.IsBound)
                    {
                        return new BuiltinFunctionInfo(md.Function, this);
                    }
                    else
                    {
                        return new BuiltinMethodInfo(md, this);
                    }
                }) ?? _noneInst);
            }
            else if (attr is IBuiltinProperty)
            {
                return(GetCached(attr, () => new BuiltinPropertyInfo((IBuiltinProperty)attr, this)) ?? _noneInst);
            }
            else if (attr is IPythonModule)
            {
                return(_modules.GetBuiltinModule((IPythonModule)attr));
            }
            else if (attr is IPythonEvent)
            {
                return(GetCached(attr, () => new BuiltinEventInfo((IPythonEvent)attr, this)) ?? _noneInst);
            }
            else if (attr is IPythonConstant)
            {
                return(GetConstant((IPythonConstant)attr).First());
            }
            else if (attrType == typeof(bool) || attrType == typeof(int) || attrType == typeof(Complex) ||
                     attrType == typeof(string) || attrType == typeof(long) || attrType == typeof(double) ||
                     attr == null)
            {
                return(GetConstant(attr).First());
            }
            else if (attr is IMemberContainer)
            {
                return(GetCached(attr, () => new ReflectedNamespace((IMemberContainer)attr, this)));
            }
            else if (attr is IPythonMultipleMembers)
            {
                IPythonMultipleMembers multMembers = (IPythonMultipleMembers)attr;
                var members = multMembers.Members;
                return(GetCached(attr, () =>
                                 MultipleMemberInfo.Create(members.Select(GetAnalysisValueFromObjects)).FirstOrDefault() ??
                                 ClassInfos[BuiltinTypeId.NoneType].Instance
                                 ));
            }
            else
            {
                var pyAttrType = GetTypeFromObject(attr);
                Debug.Assert(pyAttrType != null);
                return(GetBuiltinType(pyAttrType).Instance);
            }
        }