- //
- // Public function used to locate types, this can only
- // be used after the ResolveTree function has been invoked.
- //
- // Returns: Type or null if they type can not be found.
- //
- // Come to think of it, this should be a DeclSpace
- //
- static public Type LookupType (DeclSpace ds, string name, bool silent, Location loc)
- {
- Type t;
-
- if (ds.Cache.Contains (name)) {
- t = (Type) ds.Cache [name];
- } else {
- //
- // For the case the type we are looking for is nested within this one
- // or is in any base class
- //
- DeclSpace containing_ds = ds;
- while (containing_ds != null){
-
- // if the member cache has been created, lets use it.
- // the member cache is MUCH faster.
- if (containing_ds.MemberCache != null) {
- t = containing_ds.MemberCache.FindNestedType (name);
- if (t == null) {
- containing_ds = containing_ds.Parent;
- continue;
- }
-
- ds.Cache [name] = t;
- return t;
- }
-
- // no member cache. Do it the hard way -- reflection
- Type current_type = containing_ds.TypeBuilder;
-
- while (current_type != null &&
- current_type != TypeManager.object_type) {
- //
- // nested class
- //
- t = TypeManager.LookupType (current_type.FullName + "." + name);
- if (t != null){
- ds.Cache [name] = t;
- return t;
- }
-
- current_type = current_type.BaseType;
- }
-
- containing_ds = containing_ds.Parent;
- }
-
- t = NamespaceLookup (ds, name, silent, loc);
- if (!silent)
- ds.Cache [name] = t;
- }
-
- if (t == null && !silent)
- Report.Error (246, loc, "Cannot find type `"+name+"'");
-
- return t;
- }
-
- // <summary>
- // This is the silent version of LookupType, you can use this
- // to `probe' for a type
- // </summary>
- static public Type LookupType (TypeContainer tc, string name, Location loc)
- {
- return LookupType (tc, name, true, loc);
- }
-
- static public bool IsNamespace (string name)
- {
- Namespace ns;
-
- if (tree.Namespaces != null){
- ns = (Namespace) tree.Namespaces [name];
-
- if (ns != null)
- return true;
- }
-
- return false;
- }
-