parsing conditional compilation

Will ReSharper support parsing conditional compilation any time?

like this:

class Foo
{
#if WINDOWS
public const string Bar = "Test.";
#else
public const string Bar = "Toast.";
#endif
public static void Ooops()
{
Console.WriteLine(Bar+"Green");
}
}

ReSharper is a very nice tool, but i use things like this very often, in
bigger projects most of my files have masses of false errors that makes
ReSharper unusable.

As long as resharper can't support parsing things like this i will further
use visual-assist

A dirty but helpful workaround would be this

class Foo
{
#if WINDOWS
#region RESHARPER_IGNORE
public const string Bar = "Test.";
#endregion
#else
public const string Bar = "Toast.";
#endif
public static void Ooops()
{
Console.WriteLine(Bar+"Green");
}
}


Greets

Carsten Jendro


0
10 comments
Avatar
Permanently deleted user

oops sorry for double post and wrong date

"Carsten Jendro" <carsten.jendro@gmx.net> schrieb im Newsbeitrag
news:cd4chi$cfb$1@is.intellij.net...

Will ReSharper support parsing conditional compilation any time?

>

like this:

>

class Foo
{
#if WINDOWS
public const string Bar = "Test.";
#else
public const string Bar = "Toast.";
#endif
public static void Ooops()
{
Console.WriteLine(Bar+"Green");
}
}

>

ReSharper is a very nice tool, but i use things like this very often, in
bigger projects most of my files have masses of false errors that makes
ReSharper unusable.

>

As long as resharper can't support parsing things like this i will further
use visual-assist

>

A dirty but helpful workaround would be this

>

class Foo
{
#if WINDOWS
#region RESHARPER_IGNORE
public const string Bar = "Test.";
#endregion
#else
public const string Bar = "Toast.";
#endif
public static void Ooops()
{
Console.WriteLine(Bar+"Green");
}
}

>
>

Greets

>

Carsten Jendro

>
>


0
Avatar
Permanently deleted user

A dirty but helpful workaround would be this

class Foo
{
#if WINDOWS
#region RESHARPER_IGNORE
public const string Bar = "Test.";
#endregion
#else
public const string Bar = "Toast.";
#endif

public static void Ooops()
{
Console.WriteLine(Bar+"Green");
}
}



what about a workaround like this?
is it easy to implement to ignore specific regions complete? i think it is very similar to the solution ignoring designer generated code

0
Avatar
Permanently deleted user

I do not think that ignoring regions throughout is a good way to work with
conditional compilation. I believe, that you still would expect, for
example, that in the ignored regions code is formatted, usages are renamed
etc (as is done in "ignored" designer-generated code). A sample that you
provide is very different and more difficult than ignoring
designer-generated code. We will not be able to implement it in the 1.0
release, which is to appear in several days.

--
Andrey Simanovsky
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"



"Carsten Jendro" <no_mail@jetbrains.com> wrote in message
news:4822488.1089893021071.JavaMail.itn@is.intellij.net...

A dirty but helpful workaround would be this

>

class Foo
{
#if WINDOWS
#region RESHARPER_IGNORE
public const string Bar = "Test.";
#endregion
#else
public const string Bar = "Toast.";
#endif

>

public static void Ooops()
{
Console.WriteLine(Bar+"Green");
}
}

>
>
>

what about a workaround like this?
is it easy to implement to ignore specific regions complete? i think it is

very similar to the solution ignoring designer generated code


0
Avatar
Permanently deleted user

The error highlighting should ignore areas excluded by conditional compilation. For instance:

#if false
int var = 5;
#endif
string var = "";

The code above should not cause error indications.

0
Avatar
Permanently deleted user

That is clear, but if you, for example, wish to reformat code and set that
Int32 and String should be used instead of int and string, surely you'll
expect that it would be applied to the code under the condition, would not
you?

--
Andrey Simanovsky
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"



"Igor Postelnik" <no_mail@jetbrains.com> wrote in message
news:9171805.1089990999033.JavaMail.itn@is.intellij.net...

The error highlighting should ignore areas excluded by conditional

compilation. For instance:
>

#if false
int var = 5;
#endif
string var = "";

>

The code above should not cause error indications.

>


0
Avatar
Permanently deleted user

Well, currently (build 98) the error highlighting doesn't ignore code inside the #if false/#endif block. The only workaround is to acutally comment out the block of code. I much prefer using #if false.

I'm not sure if R# should reformat code or rename varaibles inside the #if blocks. It makes sense for real conditional compilation (e.g. special code for compact framework). So I can how it could be useful sometimes. Still, I wish R# could recognize that #if false/#endif block is not going to be compiled and didn't show errors.

0
Avatar
Permanently deleted user

I agree. I have code like this:

#if debug
return;
#endif
//reshaper makes all this code gray, because it isn't reachable

it's considerably worse when it reports a bunch of errors as opposed to the nice little green box :)

I'm sure I had an example of that, but couldn't quickly find it..

0
Avatar
Permanently deleted user

What is the " #if" and "#endif" ?
I've never seen those before in C#. Or are we discussing C++ and I just
missed it?

"karl" <no_mail@jetbrains.com> wrote in message
news:25380231.1090260028881.JavaMail.itn@is.intellij.net...

I agree. I have code like this:

>

#if debug
return;
#endif
//reshaper makes all this code gray, because it isn't reachable

>

it's considerably worse when it reports a bunch of errors as opposed to

the nice little green box :)
>

I'm sure I had an example of that, but couldn't quickly find it..



0
Avatar
Permanently deleted user

Both C# and Vb.Net have pre-processing commands, and while they aren't as advanced as C++'s, they come in quite useful. Preprocessing commands are evaluated at compile time, rather than runtime (like what you are used to). So, if I have:


when the DEBUG flag is defined, the .dll actually gets compiled as:


whereas if it isn't defined, it gets compiled as:


Granted the above code would work better suing Debug.Assert, but you get the idea.

One place I use them a lot is with caching. When debuging, I often don't want things stored in my cache, so I wrap it in something like:

#if !DEBUG_NOCACHE
HttpRuntime.Cache.Insert(cacheKey, sc, null, DateTime.Now.AddHours(6), TimeSpan.Zero);
#endif


It can be pretty useful stuff and you might want to look into it further. Here's a brief tutorial: http://www.c-sharpcenter.com/Tutorial/Preprocess.htm

0
Avatar
Permanently deleted user

I'm a fairly new programmer and have not reached that level yet ... Thanks
for the link .Any other resources I might want to consider? This is
...definitly something I need to look into. I had no idea you could send
pre-processor directives!!!!!!

"karl" <no_mail@jetbrains.com> wrote in message
news:29899185.1090266361378.JavaMail.itn@is.intellij.net...

Both C# and Vb.Net have pre-processing commands, and while they aren't as

advanced as C++'s, they come in quite useful. Preprocessing commands are
evaluated at compile time, rather than runtime (like what you are used to).
So, if I have:
>

 #if DEBUG
>    throw Exception("Expecting my string");
> #else
>    continue;
> #endif
> }]]>

>

when the DEBUG flag is defined, the .dll actually gets compiled as:

    throw Exception("Expecting my string");
> }]]>

>

whereas if it isn't defined, it gets compiled as:

    continue;
> }]]>

>

Granted the above code would work better suing Debug.Assert, but you get

the idea.
>

One place I use them a lot is with caching. When debuging, I often don't

want things stored in my cache, so I wrap it in something like:
>

#if !DEBUG_NOCACHE
HttpRuntime.Cache.Insert(cacheKey, sc, null,

DateTime.Now.AddHours(6), TimeSpan.Zero);

#endif

>
>

It can be pretty useful stuff and you might want to look into it further.

Here's a brief tutorial:
http://www.c-sharpcenter.com/Tutorial/Preprocess.htm
>



0

Please sign in to leave a comment.