ResolveResult LookInCurrentUsingScope(string identifier, IList<IType> typeArguments, bool isInUsingDeclaration, bool parameterizeResultType)
{
// look in current namespace definitions
ResolvedUsingScope currentUsingScope = this.CurrentUsingScope;
for (ResolvedUsingScope u = currentUsingScope; u != null; u = u.Parent) {
var resultInNamespace = LookInUsingScopeNamespace(u, u.Namespace, identifier, typeArguments, parameterizeResultType);
if (resultInNamespace != null)
return resultInNamespace;
// then look for aliases:
if (typeArguments.Count == 0) {
if (u.ExternAliases.Contains(identifier)) {
return ResolveExternAlias(identifier);
}
if (!(isInUsingDeclaration && u == currentUsingScope)) {
foreach (var pair in u.UsingAliases) {
if (pair.Key == identifier) {
return pair.Value.ShallowClone();
}
}
}
}
// finally, look in the imported namespaces:
if (!(isInUsingDeclaration && u == currentUsingScope)) {
IType firstResult = null;
foreach (var importedNamespace in u.Usings) {
ITypeDefinition def = importedNamespace.GetTypeDefinition(identifier, typeArguments.Count);
if (def != null) {
IType resultType;
if (parameterizeResultType && typeArguments.Count > 0)
resultType = new ParameterizedType(def, typeArguments);
else
resultType = def;
if (firstResult == null || !TopLevelTypeDefinitionIsAccessible(firstResult.GetDefinition())) {
if (TopLevelTypeDefinitionIsAccessible(resultType.GetDefinition()))
firstResult = resultType;
} else if (TopLevelTypeDefinitionIsAccessible(def)) {
return new AmbiguousTypeResolveResult(firstResult);
}
}
}
if (firstResult != null)
return new TypeResolveResult(firstResult);
}
// if we didn't find anything: repeat lookup with parent namespace
}
return null;
}