Created
February 18, 2012 16:29
-
-
Save dgrunwald/1860065 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IType Resolve(ITypeResolveContext context) | |
{ | |
string[] parts = typeName.Split('.'); | |
var assemblies = new [] { context.CurrentAssembly, context.Compilation.MainAssembly }.Concat(context.Compilation.ReferencedAssemblies); | |
for (int i = parts.Length - 1; i >= 0; i++) { | |
string ns = string.Join(".", parts, 0, i); | |
string name = parts[i]; | |
int topLevelTPC = (i == parts.Length - 1 ? typeParameterCount : 0); | |
foreach (var asm in assemblies) { | |
if (asm == null) | |
continue; | |
ITypeDefinition typeDef = asm.GetTypeDefinition(ns, name, topLevelTPC); | |
for (int j = i + 1; j < parts.Length && typeDef != null; j++) { | |
int tpc = (j == parts.Length - 1 ? typeParameterCount : 0); | |
typeDef = typeDef.NestedTypes.FirstOrDefault(n => n.Name == parts[j] && n.TypeParameterCount == tpc); | |
} | |
if (typeDef != null) | |
return typeDef; | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment