提交 82661a3d 编写于 作者: K Kevin_H

Test helpers: Enable lookup of names with dots (explicit interface...

Test helpers:  Enable lookup of names with dots (explicit interface implementation) and generate more useful messages when member lookup fails. (changeset 1396244)
上级 febe9e5b
...@@ -168,7 +168,13 @@ public static Symbol GetMember(this Compilation compilation, string qualifiedNam ...@@ -168,7 +168,13 @@ public static Symbol GetMember(this Compilation compilation, string qualifiedNam
public static ImmutableArray<Symbol> GetMembers(this Compilation compilation, string qualifiedName) public static ImmutableArray<Symbol> GetMembers(this Compilation compilation, string qualifiedName)
{ {
NamespaceOrTypeSymbol lastContainer; NamespaceOrTypeSymbol lastContainer;
return GetMembers(((CSharpCompilation)compilation).GlobalNamespace, qualifiedName, out lastContainer); var members = GetMembers(((CSharpCompilation)compilation).GlobalNamespace, qualifiedName, out lastContainer);
if (members.IsEmpty)
{
Assert.True(false, string.Format("Could not find member named '{0}'. Available members:\r\n{1}",
qualifiedName, string.Join("\r\n", lastContainer.GetMembers().Select(m => "\t\t" + m.Name))));
}
return members;
} }
private static ImmutableArray<Symbol> GetMembers(NamespaceOrTypeSymbol container, string qualifiedName, out NamespaceOrTypeSymbol lastContainer) private static ImmutableArray<Symbol> GetMembers(NamespaceOrTypeSymbol container, string qualifiedName, out NamespaceOrTypeSymbol lastContainer)
...@@ -178,7 +184,17 @@ private static ImmutableArray<Symbol> GetMembers(NamespaceOrTypeSymbol container ...@@ -178,7 +184,17 @@ private static ImmutableArray<Symbol> GetMembers(NamespaceOrTypeSymbol container
lastContainer = container; lastContainer = container;
for (int i = 0; i < parts.Length - 1; i++) for (int i = 0; i < parts.Length - 1; i++)
{ {
lastContainer = (NamespaceOrTypeSymbol)lastContainer.GetMember(parts[i]); var nestedContainer = (NamespaceOrTypeSymbol)lastContainer.GetMember(parts[i]);
if (nestedContainer == null)
{
// If there wasn't a nested namespace or type with that name, assume it's a
// member name that includes dots (e.g. explicit interface implementation).
return lastContainer.GetMembers(string.Join(".", parts.Skip(i)));
}
else
{
lastContainer = nestedContainer;
}
} }
return lastContainer.GetMembers(parts[parts.Length - 1]); return lastContainer.GetMembers(parts[parts.Length - 1]);
...@@ -190,7 +206,7 @@ public static Symbol GetMember(this NamespaceOrTypeSymbol container, string qual ...@@ -190,7 +206,7 @@ public static Symbol GetMember(this NamespaceOrTypeSymbol container, string qual
var members = GetMembers(container, qualifiedName, out lastContainer); var members = GetMembers(container, qualifiedName, out lastContainer);
if (members.Length == 0) if (members.Length == 0)
{ {
Assert.True(false, "Available members:\r\n" + string.Join("\r\n", lastContainer.GetMembers())); return null;
} }
else if (members.Length > 1) else if (members.Length > 1)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册