Skip to content

Instantly share code, notes, and snippets.

@dgrunwald
Created February 18, 2012 16:29
Show Gist options
  • Save dgrunwald/1860065 to your computer and use it in GitHub Desktop.
Save dgrunwald/1860065 to your computer and use it in GitHub Desktop.
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