private Type GetType(string assemblyName, string className)
{
Debug.Assert(className != null, "classname can't be null");
Debug.Assert(assemblyName != null, "Assembly name can't be null");
// combine assembly name and class name for unique indexing
string fullName = assemblyName + ":" + className;
Type type;
if (_typeCache.ContainsKey(fullName))
{
// we found it in the cache, so just return
return _typeCache[fullName];
}
// we didn't find it in the table. So let's get to the assembly first
Assembly assembly = null;
if (_assemblies != null && _assemblies.ContainsKey(assemblyName))
{
// find the assembly in the hash table first
assembly = _assemblies[assemblyName];
}
if (assembly == null)
{
// we don't find the assembly in the hashtable
// try to use the default well known assemblies
int index;
if ( (index = Array.BinarySearch(
_wellKnownAssemblyNames,
GetAssemblyShortName(assemblyName).ToLower(CultureInfo.InvariantCulture)
)
) >= 0
)
{
// see if we already loaded the assembly
if (_wellKnownAssemblies[index] == null)
{
// it is a well known name, load it from the gac
_wellKnownAssemblies[index] = Assembly.Load(assemblyName);
}
assembly = _wellKnownAssemblies[index];
}
}
if (assembly != null)
{
// So, we found the assembly. Now get the type from the assembly
type = assembly.GetType(className);
}
else
{
// Couldn't find the assembly. We will try to load it
type = null;
}
// remember what we found out.
_typeCache[fullName] = type;
return type; // return
}