Created
April 22, 2014 09:28
-
-
Save CraftyFella/11171780 to your computer and use it in GitHub Desktop.
Type Extensions...
This file contains 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 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