Created
February 16, 2017 23:32
-
-
Save ajai8085/d3517c53d908eb6481ebf2270805d5ec to your computer and use it in GitHub Desktop.
Get all instances of custom attribute defined only for classes with allowmultiple=false , useful when using FluentMigrator
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 AssemblyExtensions{ | |
public static List<TCustomAttribute> GetAllCustomAttributeInstances<TCustomAttribute>(this Assembly assembly) | |
where TCustomAttribute : Attribute | |
{ | |
var supportedMigrationVersions = assembly | |
.GetTypes() | |
.Where(t => Attribute.IsDefined(t, typeof(TCustomAttribute))) | |
.Select(t => (t.GetCustomAttribute(typeof(TCustomAttribute)) as TCustomAttribute)) | |
.ToList(); | |
return supportedMigrationVersions; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment