Skip to content

Instantly share code, notes, and snippets.

@jbogard
Created January 13, 2015 00:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
public class ContravariantFilter : IHandlersFilter
{
public bool HasOpinionAbout(Type service)
{
if (!service.IsGenericType)
return false;
var genericType = service.GetGenericTypeDefinition();
var genericArguments = genericType.GetGenericArguments();
return genericArguments.Count() == 1
&& genericArguments.Single().GenericParameterAttributes.HasFlag(GenericParameterAttributes.Contravariant);
}
public IHandler[] SelectHandlers(Type service, IHandler[] handlers)
{
return handlers;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment