public virtual AliasDefinition GetAliasDefinitionForRoot(Expression qualOrId, NamespaceScope nsscope){
   if (nsscope == null) return null;
   if (qualOrId == null){Debug.Assert(false); return null;}
   QualifiedIdentifier qual = qualOrId as QualifiedIdentifier;
   if (qual != null) return this.GetAliasDefinitionForRoot(qual.Qualifier, nsscope);
   Identifier id = qualOrId as Identifier;
   if (id == null){Debug.Assert(false); return null;}
   NamespaceScope outerScope = nsscope.OuterScope as NamespaceScope;
   if (id.Prefix != null){
     AliasDefinition aliasDef = nsscope.GetAliasFor(id.Prefix);
     if (aliasDef != null && aliasDef.AliasedAssemblies != null) return aliasDef;
     if (outerScope == null) return null;
     return outerScope.GetAliasFor(id.Prefix);
   }else{
     AliasDefinition aliasDef = nsscope.GetAliasFor(id);
     if (aliasDef != null && aliasDef.AliasedAssemblies != null) return aliasDef;
     if (outerScope == null) return null;
     return outerScope.GetAliasFor(id);
   }
 }
 public virtual Node LookupTypeOrNamespace(Identifier identifier, bool typeOnly, NamespaceScope nsScope, out TypeNodeList duplicates){
   duplicates = null;
   if (identifier == null || nsScope == null){Debug.Assert(false); return null;}
   TypeNode t = nsScope.GetType(identifier, out duplicates, true);
   if (t != null && t.Name != null && t.Name.UniqueIdKey == identifier.UniqueIdKey){
     AliasDefinition aliasDef = nsScope.GetConflictingAlias(identifier);
     if (aliasDef != null) aliasDef.ConflictingType = t;
   }else if (!typeOnly){
     TrivialHashtable alreadySeenAliases = new TrivialHashtable();
     AliasDefinition aliasDef = nsScope.GetAliasFor(identifier);
     while (aliasDef != null){
       if (aliasDef.AliasedType != null) return (TypeNode)aliasDef.AliasedType;
       if (alreadySeenAliases[aliasDef.UniqueKey] != null) break; //TODO: error?
       alreadySeenAliases[aliasDef.UniqueKey] = aliasDef;
       if (aliasDef.AliasedAssemblies != null) return aliasDef;
       if (aliasDef.AliasedExpression is Identifier)
         aliasDef = nsScope.GetAliasFor(identifier = (Identifier)aliasDef.AliasedExpression);
       else if (aliasDef.AliasedExpression is QualifiedIdentifier)
         return this.LookupTypeOrNamespace(aliasDef.AliasedExpression, false);
       else
         aliasDef = null; 
     }
     Identifier ns = nsScope.GetNamespaceFullNameFor(identifier);
     if (ns != null) return ns;
   }
   return t;
 }
 public virtual void ExpandRootIfAnAlias(ref Expression qualOrId, NamespaceScope nsscope){
   if (nsscope == null) return;
   if (qualOrId == null){Debug.Assert(false); return;}
   QualifiedIdentifier qual = qualOrId as QualifiedIdentifier;
   if (qual != null){this.ExpandRootIfAnAlias(ref qual.Qualifier, nsscope); return;}
   Identifier id = qualOrId as Identifier;
   if (id == null) return;
   NamespaceScope outerScope = nsscope.OuterScope as NamespaceScope;
   if (id.Prefix != null){
     AliasDefinition aliasDef = nsscope.GetAliasFor(id.Prefix);
     if (aliasDef != null && aliasDef.AliasedAssemblies != null){
       //TODO: pass it back up to the caller
       return;
     }
     if (outerScope == null) return;
     aliasDef = outerScope.GetAliasFor(id.Prefix);
     if (aliasDef != null){
       qualOrId = new QualifiedIdentifier(aliasDef.AliasedExpression, this.GetUnprefixedIdentifier(id), id.SourceContext);
       return;
     }
   }else{
     AliasDefinition aliasDef = nsscope.GetAliasFor(id);
     if (aliasDef != null && aliasDef.AliasedAssemblies != null){
       //TODO: pass it back up to the caller
       return;
     }
     if (outerScope == null) return;
     aliasDef = outerScope.GetAliasFor(id);
     if (aliasDef != null){
       qualOrId = aliasDef.AliasedExpression;
       return;
     }
   }
 }