Attribute[] GetCustomAttributes(Assembly element, Type attributeType) method returns array of the custom attributes applied to an assembly. Attributes applied to assembly look like
[assembly: AssemblyCompany("Microsoft")]
Your attribute is not applied to assembly. Use following code to get custom attributes applied to State
field:
var memberInfo = typeof(PhaseState).GetField("State");
Attribute[] supportingAttributes =
Attribute.GetCustomAttributes(memberInfo, typeof(OptimizableNominalAttribute));
If you want to check all public members in assembly which have this attribute, you can use following query:
var attributeType = typeof(OptimizableNominalAttribute);
var supportingAttributes = theAssembly.GetTypes()
.SelectMany(t => t.GetMembers()) // you can pass binding flags here
.SelectMany(m => Attribute.GetCustomAttributes(m, attributeType));
Query syntax:
var supportingAttributes =
from t in theAssembly.GetTypes()
from m in t.GetMembers()
from a in Attribute.GetCustomAttributes(m, attributeType)
select a;