[Conditional("DEBUG")] attributes

M

Manish Agarwal

Is there anything similar to [Conditional("DEBUG")] attributes in
csharp (http://msdn.microsoft.com/en-us/library/aa288458(VS.71).aspx)

where I can supply a variable instead of "DEBUG" or other define.

I have few methods which I want to call only when a global variable is
true. something like

if (myGlobalFlagOn)
{
// compute param1, param2, param3 here
SomeObject.MethodCall(param1, param2, param3)
}

I don't want to use too many if conditions. I can have some wrapper
functions which can internally check the state of the variable inside
but in that case I need to always compute param1, param2, param3
parameters even if we are not going to use them.

Regards,
Manish
 
P

Patrice

Hi
where I can supply a variable instead of "DEBUG" or other define.

It can't be a variable as it happens at compile time. Not sure why you need
a variable (to know if the code was compiled with or without the define ?)
but you could perhaps do it the other way round that is you could use #if to
define the constant depending to distinct value depending on the define
being defined or undefined...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top