I have an enum where each member has a custom attribute applied to it. How can I retrieve the value stored in each attribute?
Right now I do this:
var attributes = typeof ( EffectType ).GetCustomAttributes ( false );
foreach ( object attribute in attributes )
{
GPUShaderAttribute attr = ( GPUShaderAttribute ) attribute;
if ( attr != null )
return attr.GPUShader;
}
return 0;
Another issue is, if it's not found, what should I return? 0 is implcity convertible to any enum, right? That's why I returned that.
Forgot to mention, the above code returns 0 for every enum member.
See Question&Answers more detail:os