У меня есть перечисление, в котором каждый член имеет свой собственный атрибут. Как я могу получить значение, сохраненное в каждом атрибуте?
Сейчас я делаю это:
var attributes = typeof ( EffectType ).GetCustomAttributes ( false );
foreach ( object attribute in attributes )
{
GPUShaderAttribute attr = ( GPUShaderAttribute ) attribute;
if ( attr != null )
return attr.GPUShader;
}
return 0;
Еще одна проблема: если она не найдена, что я должен вернуть? 0 - это трансформируемость сжимаемости в любое перечисление, не так ли? Вот почему я вернул это.
Забытый, приведенный выше код возвращает 0 для каждого члена перечисления.