#if for LINQPad
It would be great if LINQPad could use #if (http://msdn.microsoft.com/en-us/library/4y6tbswk.aspx) and #define for LINQPad queries .
For example, to avoid nested classes I add two closing braces after the Main() function and omit closing the last class in my LINQPad file (http://solutionevangelist.com/discussion/12/linqpad-and-ef-code-first-ado.net-entity-framework-ctp5)
In fact, we wouldn't have to use #define either if there was just a default #define LINQPAD for all queries. Then we could bypass Util.ReadLine() methods, etc.

You can now define symbols and use conditional compilation directives in LINQPad.
-
Maslow commented
does this only happen in C# queries? it doesn't appear to be working for me in F# Program mode
-
Maslow commented
I don't believe the solution is very usable with F#, since F# doesn't allow #define but does allow #if
I'd love it if linqpad or LINQPAD was always defined when running types that support #if (all but SQL/ESQL) -
Joe: this feature will it will be in the next build (not the current one). v4.34 will appear on the beta page in a day or two.
-
Joe S commented
I have downloaded the beta and attempted to define my own pre-processor directive. I still get a compile error "Cannot define/undefine preprocessor symbols after first token in file".
So I thought maybe LINQPad is expecting these directives to be defined in the query properties... much in the same manner as a "using" is implemented within LINQPad... in the Query Properties ... Additonal Namespace Imports tab.... still no joy.... compile error is "Preprocessor directives must appear as the first non-whitespace character on a line"
So tell me Joe... how is this implemented? Where do I define my own pre-processor directives?
Thanks.
-
Joe S commented
Defining a LINQPAD pre-processor directive will be use... I agree. But allowing for user defined pre-processor directives is really what I would prefer to see. This would offer more control. The use case that I will cite is where I am displaying class instance variables via [variable_name].Dump() . I may wish to hide some data as the default and only display the data when implementing the #define. I would like to be able to use the following pattern....
#define VERBOSE
..
..
Widget widget = new Widget();
widget.Dump();
..
..
public class Widget
..
..
..
#if verbose
public string TheProperty
#else
internal string TheProperty
#endif
{
set
{ this.theProperty = value; }
get { return this.theProperty; }
}