Skip to content

Instantly share code, notes, and snippets.

@ajai8085
Created February 16, 2017 23:32
Show Gist options
  • Save ajai8085/d3517c53d908eb6481ebf2270805d5ec to your computer and use it in GitHub Desktop.
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
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