Skip to content

Instantly share code, notes, and snippets.

@timwingfield
Created March 5, 2010 14:52
Show Gist options
  • Save timwingfield/322769 to your computer and use it in GitHub Desktop.
Save timwingfield/322769 to your computer and use it in GitHub Desktop.
public class RepositoryConventionScanner : IRegistrationConvention
{
public void Process(Type type, Registry registry)
{
Type repoForType = GetGenericParamFor(type.BaseType, typeof(Repository<>));
if (repoForType != null)
{
var genType = typeof(IRepository<>).MakeGenericType(repoForType);
registry.For(genType).Add(typeof (Repository<>));
}
}
private static Type GetGenericParamFor(Type typeToInspect, Type genericType)
{
if(typeToInspect != null && typeToInspect.IsGenericType && typeToInspect.GetGenericTypeDefinition().Equals(genericType))
{
return typeToInspect.GetGenericArguments()[0];
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment