예제 #1
0
        private static Type ResolveBaseTypePath(TypeLookup typeLookup, IReadOnlyList <string> namespaces)
        {
            Type retn = ResolveSimpleType(typeLookup.typeName);

            if (retn != null)
            {
                return(retn);
            }

            string baseTypeName = "." + typeLookup.GetBaseTypeName(); // save some string concat

            if (!string.IsNullOrEmpty(typeLookup.namespaceName))
            {
                LightList <Assembly> assemblies = s_NamespaceMap.GetOrDefault(typeLookup.namespaceName);

                if (assemblies == null)
                {
                    throw new TypeResolutionException($"No loaded assemblies found for namespace {typeLookup.namespaceName}");
                }

                string typename = typeLookup.namespaceName + baseTypeName;

                for (int a = 0; a < assemblies.Count; a++)
                {
                    retn = assemblies[a].GetType(typename);
                    if (retn != null)
                    {
                        return(retn);
                    }
                }

                LightList <Assembly> lastDitchAssemblies = s_NamespaceMap.GetOrDefault("null");
                if (lastDitchAssemblies != null)
                {
                    typename = typeLookup.typeName;
                    for (int a = 0; a < lastDitchAssemblies.Count; a++)
                    {
                        retn = lastDitchAssemblies[a].GetType(typename);
                        if (retn != null)
                        {
                            return(retn);
                        }
                    }
                }
            }
            else
            {
                if (namespaces != null)
                {
                    for (int i = 0; i < namespaces.Count; i++)
                    {
                        LightList <Assembly> assemblies = s_NamespaceMap.GetOrDefault(namespaces[i]);
                        if (assemblies == null)
                        {
                            continue;
                        }

                        string typename = namespaces[i] + baseTypeName;
                        for (int a = 0; a < assemblies.Count; a++)
                        {
                            retn = assemblies[a].GetType(typename);
                            if (retn != null)
                            {
                                return(retn);
                            }
                        }
                    }
                }

                LightList <Assembly> lastDitchAssemblies = s_NamespaceMap.GetOrDefault("null");
                if (lastDitchAssemblies != null)
                {
                    string typename = typeLookup.typeName;
                    for (int a = 0; a < lastDitchAssemblies.Count; a++)
                    {
                        retn = lastDitchAssemblies[a].GetType(typename);
                        if (retn != null)
                        {
                            return(retn);
                        }
                    }
                }
            }

            if (namespaces != null && namespaces.Count > 0 && namespaces[0] != string.Empty)
            {
                string checkedNamespaces = string.Join(",", namespaces.ToArray());
                throw new TypeResolutionException($"Unable to resolve type {typeLookup}. Looked in namespaces: {checkedNamespaces}");
            }
            else
            {
                throw new TypeResolutionException($"Unable to resolve type {typeLookup}.");
            }
        }