473,320 Members | 1,948 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,320 software developers and data experts.

Detect if assembly is compiled as debug

Is it possible in c# to detect if an assembly is compiled with the
DEBUG option?

I want to add attributes to some classes, that will do different
things depending on whether the class is build as debug or not.

Thanks in advance.
Nov 16 '05 #1
3 5624
You can use #ifdef as follows

#ifdef DEBUG
[MyAttribute("foo")]
#endif
class Foo
{
}

In this case the MyAttribute will only apply to the class Foo if the assembly is compiled with the DEBUG symbol defined.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Is it possible in c# to detect if an assembly is compiled with the
DEBUG option?

I want to add attributes to some classes, that will do different
things depending on whether the class is build as debug or not.

Thanks in advance.

Nov 16 '05 #2
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()
{
....
}
}

Nov 16 '05 #3
You can't directly determine wheather a class was compiled with Debug or
not.
But you can, for example use System.Diagnostics.Debugger.IsAttached to
determine if the running program is currently debugged.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
<tg********@yahoo.co.uk> schrieb im Newsbeitrag
news:11**********************@f14g2000cwb.googlegr oups.com...
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()
{
....
}
}

Nov 16 '05 #4

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

Similar topics

1
by: andrej | last post by:
hi, i have a nt-service. which throws sometimes an exception. the exception is caught in a catch block. is it possible to print out a line which cause the exception? thanks
0
by: Jazper | last post by:
hi got a foolish question. - when i add to my csharp-application a debug-compiled-assembly also written in csharp, i can step into it when debugging my app. - when i add my...
2
by: Gawel | last post by:
thanks in advance -- Gawel ------------------------------- Pierwszy ³yk z pucharu nauk przyrodniczych czyni ateist±, ale na dnie pucharu czeka Bóg. Werner Heisenberg
3
by: Jim | last post by:
Hi, I have an assembly and it's satellite in my GAC. I have referenced the DLLs in my project (from the same location where I added it to the GAC). CopyLocal is set false. When I run the...
0
by: Shawn Hogan | last post by:
I'm getting two different results when I call System.Reflection.Assembly.GetCallingAssembly when compiling in Release and debug modes. When i compile my application using the "Debug" configuration...
2
by: john | last post by:
Maybe I haven't had that "a-ha" moment yet, but I think the new approach to web projects is a step in the wrong direction. My main beef is that control over the assembly generation process has...
2
by: יוני גולדברג | last post by:
I'm using Dot Net Nuke but this general question: I'm trying to debug the registration code, whenever i set breakpoint on the main function i get message: "breakpoint will not be hit, no symbols...
7
by: bonk | last post by:
I have a c# project as part of a larger VS 2005 solution that always gets build optimized and I therefore can not evaluate any values while debugging through the code ("Cannot evaluate expression...
13
by: Bob Altman | last post by:
Hi all, I have authored several native DLLs (call them A, B, and C). These libraries have references between each other (A calls B which calls C). These libraries are built and made available...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.