Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Design Mode" preprocessor directive

I have a problem on displaying a component in Designer.

I identified the "bad" code that the designer does not like.

Now, the problem is that I can't "comment" it for design time only using preprocessor directives.

Now, I tried (for VB.NET) the following

#If Not Debug Then
Private Sub myWpfComponent_ItsEvent(sender, args) Handles myWpfComponent.ItsEvent
...
#End If 

this... worked, and now it is displayed without problems in the designer.

The problem now that I am afraid do not be able to debug properly this component.

So, I am searching for a workaround à la

#If Not DESIGN_TIME Then
#End If 

Is there something similar?

like image 577
serhio Avatar asked Jan 27 '11 20:01

serhio


People also ask

What are the two most common kinds of preprocessor directives?

There are 4 Main Types of Preprocessor Directives:Macros. File Inclusion. Conditional Compilation. Other directives.

What is preprocessor directive section?

Preprocessor directives are lines of the source file where the first non-whitespace character is # , which distinguishes them from other lines of text. The effect of each preprocessor directive is a change to the text and the result is a transformation of the text that does not contain the directives nor comments.

Which symbol is used for preprocessor directive?

All Preprocessor directives begin with the # (hash) symbol. C++ compilers use the same C preprocessor. The preprocessor is a part of the compiler which performs preliminary operations (conditionally compiling code, including files etc...) to your code before the compiler sees it.

What is preprocessor directive in asp net?

As the name justifies, preprocessor directives are a block of statements that gets processed before the actual compilation starts. C# preprocessor directives are the commands for the compiler that affects the compilation process.


1 Answers

You cannot achieve this through the preprocessor. This is because you can run a debug executable outside of VS (try it, double click on the EXE generated by VS under debug mode).

Anyway, there is a runtime (not preprocessor based) property that might help:

if (System.ComponentModel.LicenseManager.UsageMode ==
    System.ComponentModel.LicenseUsageMode.Designtime)

These web pages will help and have other methods of checking for design mode at runtime:

http://msdn.microsoft.com/en-us/library/c58hb4bw(vs.71).aspx

http://weblogs.asp.net/fmarguerie/archive/2005/03/23/395658.aspx

like image 181
Gabriel Magana Avatar answered Oct 08 '22 23:10

Gabriel Magana