Skip to content

Instantly share code, notes, and snippets.

@CraftyFella
Created April 22, 2014 09:28
Show Gist options
  • Save CraftyFella/11171780 to your computer and use it in GitHub Desktop.
Save CraftyFella/11171780 to your computer and use it in GitHub Desktop.
Type Extensions...
public static class TypeExtensions
{
public static bool HasAttribute<TAttribute>(this Type type) where TAttribute : Attribute
{
return type.CustomAttributes.Any(a => a.AttributeType == typeof (TAttribute));
}
public static IEnumerable<Type> DerivedTypesFrom<T>(this Assembly assembly)
{
return assembly.GetTypes().Where(typeof(T).IsAssignableFrom);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment