To get attributes from a class, you can do something like the following:
typeof(youClass).GetCustomAttributes<YourAttribute>(); // or // if you need only one attribute typeof(youClass).GetCustomAttribute<YourAttribute>();
it will return an IEnumerable<YourAttribute> .
So in your code this will be something like:
Assembly.GetEntryAssembly() .GetTypes() .AsEnumerable() .Where(type => typeof(Controller).IsAssignableFrom(type)) .ToList() .ForEach(d => { var yourAttributes = d.GetCustomAttributes<YourAttribute>();
Edit:
In the case of CoreCLR, you need to call another method because the API has been slightly modified:
typeof(youClass).GetTypeInfo().GetCustomAttributes<YourAttribute>();
MaKCbIMKo
source share