473,397 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

"Conditional" attribute confusion

I use VS2005 with framework 2.0 and I just found a behavior I consider odd.
Here is the code that illustrates th eproblem:

[Conditional("DEBUG")]
public static void MethodA()
{
MethodB()
}

#if DEBUG
public static void MethodB()
{
....
}
#endif

my expectation was that this code will compile perfectly when DEBUG
condition is defined as well as when it is undefined. Apparently, that is
not the case. When compiling with "DEBUG" undefined, compiler generates
error: "The name MethodB does not exist in current context."

This is what Microsoft help says about ConditionalAttribute class:
"Indicates to compilers that a method call or attribute should be ignored
unless a specified conditional compilation symbol is defined". The
conclusion from this is that MethodA from my example should not be compiled.
The reality is that the nethod is compiled - otherwise the error would not
have been reported.

Is there something I am missing about "Conditional" attribute and how the
compiler is working or it something .NET framework documentation or/and C#
compiler are missing ?

Thank you.
Nov 16 '06 #1
1 2266
Well, 2 minutes after I submitted this post I found the answer to my
question. Certainly it was me missing the point. "Conditional" attribute
informs compiler to ignore the call to the method but not to ignore the
method during the compilation.

My apology for posting something that I should not have.


>I use VS2005 with framework 2.0 and I just found a behavior I consider odd.
Here is the code that illustrates th eproblem:

[Conditional("DEBUG")]
public static void MethodA()
{
MethodB()
}

#if DEBUG
public static void MethodB()
{
...
}
#endif

my expectation was that this code will compile perfectly when DEBUG
condition is defined as well as when it is undefined. Apparently, that is
not the case. When compiling with "DEBUG" undefined, compiler generates
error: "The name MethodB does not exist in current context."

This is what Microsoft help says about ConditionalAttribute class:
"Indicates to compilers that a method call or attribute should be ignored
unless a specified conditional compilation symbol is defined". The
conclusion from this is that MethodA from my example should not be
compiled. The reality is that the nethod is compiled - otherwise the
error would not have been reported.

Is there something I am missing about "Conditional" attribute and how the
compiler is working or it something .NET framework documentation or/and C#
compiler are missing ?

Thank you.


Nov 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: delerious | last post by:
I see some code examples like this: <DIV onmouseover="this.style.background='blue'"> and other code examples like this: <DIV onmouseover="javascript:this.style.background='blue'"> Which...
6
by: Allan Koch | last post by:
Dear NG, I would like to format a record in a subform, dependent on a value in one field. If one field in the record I show in a subform (datasheet view) is true I like to view that particular...
10
by: John Smith | last post by:
After reading C# documentation the Conditional attribute seemed the way to go, but after inspecting the IL it seems those methods are still there and I imagine the CLR removes them. Using #if DEBUG...
3
by: ARZ | last post by:
Hi How do I include DLLs based on a condition. Eg., there are 2 DLLs 'Oracle.dll' and 'SQL.dll'. I need to include ANYONE of the DLLs based on a value. Is it possile in C# Thanks in advance ARZ
2
by: JC | last post by:
I am trying to conditionally print a field on a report based on the value of another field in the query that the report is based on. In the Control Source for SerialB I have typed: = IIF(nz(QtyB)...
7
by: What-A-Tool | last post by:
In the following code, "catch" is underlined in blue, and the error "the variable fx is declared but never used" is displayed when I mouse hover over it. Am I doing something wrong, or do I just...
1
by: cyningeston | last post by:
OS: WinXP Pro, VB/ASP/ADO.NET I'm building a web-based supplier management application. For each supplier we are required by the FDA to track certain documents. I've managed to pull them from...
1
by: Christian Welzel | last post by:
Hi there! Currently i'm thinking about how to solve this problem: if (t3lib_div::int_from_ver(phpversion())<5000000) { // php4 class tx_lib_object extends tx_lib_selfAwareness {...} // }...
1
by: veaux | last post by:
Question deals with linking tables in queries. I'm not a code writer so use the GUI for all my queries. Table 1 - Master Table 2 - Sub1 Table 3 - Sub 2 All 3 tables have the same key field....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.