Richard Blewett [DevelopMentor] wrote:
You can use #ifdef as follows
#ifdef DEBUG
[MyAttribute("foo")]
#endif
class Foo
{
}
Not quite....
I want to do different things with the Attribute if the class which
contains the attribute is compiled with debug info...
e.g.
System.Type type = obj.GetType();
MemberInfo[] members = type.GetMembers();
for ( int i = 0; i < members.Length; i++ )
{
object[] attributes =
members[i].GetCustomAttributes(false);
for ( int j = 0; j < attributes.Length; j++ )
{
if ( attribute[j] is MyAttribute &&
obj.IsCompiledWithDebug )
{
// do something
}
else
{
// do something else
}
}
where obj is of type Foo, which is defined as in your example:
class Foo
{
[MyAttribute("foo")]
public void Bar()
{
....
}
}