- static Hashtable negative_hits = new Hashtable ();
-
- //
- // This function is used when you want to avoid the lookups, and want to go
- // directly to the source. This will use the cache.
- //
- // Notice that bypassing the cache is bad, because on Microsoft.NET runtime
- // GetType ("DynamicType[]") != GetType ("DynamicType[]"), and there is no
- // way to test things other than doing a fullname compare
- //
- public static Type LookupTypeDirect (string name)
- {
- Type t = (Type) types [name];
- if (t != null)
- return t;
-
- t = LookupTypeReflection (name);
- if (t == null)
- return null;
-
- types [name] = t;
- return t;
- }
-
- static readonly char [] dot_array = { '.' };
-
- /// <summary>
- /// Returns the Type associated with @name, takes care of the fact that
- /// reflection expects nested types to be separated from the main type
- /// with a "+" instead of a "."
- /// </summary>
- public static Type LookupType (string name)
- {
- Type t;
-
- //
- // First lookup in user defined and cached values
- //
-
- t = (Type) types [name];
- if (t != null)
- return t;
-
- // Two thirds of the failures are caught here.
- if (negative_hits.Contains (name))
- return null;
-
- // Sadly, split takes a param array, so this ends up allocating *EVERY TIME*
- string [] elements = name.Split (dot_array);
- int count = elements.Length;
-
- for (int n = 1; n <= count; n++){
- string top_level_type = String.Join (".", elements, 0, n);
-
- // One third of the failures are caught here.
- if (negative_hits.Contains (top_level_type))
- continue;
-
- t = (Type) types [top_level_type];
- if (t == null){
- t = LookupTypeReflection (top_level_type);
- if (t == null){
- negative_hits [top_level_type] = null;
- continue;
- }
- }
-
- if (count == n){
- types [name] = t;
- return t;
- }
-
- //
- // We know that System.Object does not have children, and since its the parent of
- // all the objects, it always gets probbed for inner classes.
- //
- if (top_level_type == "System.Object")
- return null;
-
- string newt = top_level_type + "+" + String.Join ("+", elements, n, count - n);
- //Console.WriteLine ("Looking up: " + newt + " " + name);
- t = LookupTypeReflection (newt);
- if (t == null)
- negative_hits [name] = null;
- else
- types [name] = t;
- return t;
- }
- negative_hits [name] = null;
- return null;
- }
-