The Conditional attribute to control execution of parts of the code in C# .NET

In this post we saw how to use the #if preprocessor to control the execution of code. The compiler will understand those instructions and compile away bits of code.

There’s another way to achieve something similar using the Conditional attribute. You can decorate methods with this attribute. It accepts a string parameter which defines the name of the symbol that must be defined in order for the method to be carried out.

Read more of this post

Advertisements

How to emit compiler warnings and errors in C# .NET

In this post we saw how to use the “if” preprocessor in Visual Studio to “communicate” with the compiler. Here’s a reminder of the example code which we’ll re-use here:

private static void TryPreprocessors()
{
# if DEBUG
	Console.WriteLine("You are running the Debug build");
# elif RELEASE
	Console.WriteLine("You are running the Release build");
#else
	Console.WriteLine("This is some other build.");
# endif
}

In this post we’ll look at two more preprocessor types: warning and error. If you compile a project you can get one or more errors or warnings:

Read more of this post

The Conditional attribute to control execution of parts of the code in C# .NET

In this post we saw how to use the #if preprocessor to control the execution of code. The compiler will understand those instructions and compile away bits of code.

There’s another way to achieve something similar using the Conditional attribute. You can decorate methods with this attribute. It accepts a string parameter which defines the name of the symbol that must be defined in order for the method to be carried out.

Read more of this post

How to emit compiler warnings and errors in C# .NET

In this post we saw how to use the “if” preprocessor in Visual Studio to “communicate” with the compiler. Here’s a reminder of the example code which we’ll re-use here:

private static void TryPreprocessors()
{
# if DEBUG
	Console.WriteLine("You are running the Debug build");
# elif RELEASE
	Console.WriteLine("You are running the Release build");
#else
	Console.WriteLine("This is some other build.");
# endif
}

In this post we’ll look at two more preprocessor types: warning and error. If you compile a project you can get one or more errors or warnings:

Read more of this post

The ‘if’ preprocessor directive for the compiler in C# .NET

You can decorate your C# source code with “messages” to the compiler. There are a couple of predefined preprocessors that the compiler understands.

A common scenario is when you’d like to run some part of your code in Debug mode but not in Release mode or any other Build type. The following method shows the ‘if’ and ‘elif’ preprocessors:

Read more of this post

ultimatemindsettoday

A great WordPress.com site

Elliot Balynn's Blog

A directory of wonderful thoughts

Softwarearchitektur in der Praxis

Wissenswertes zu Webentwicklung, Domain-Driven Design und Microservices

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

WEB APPLICATION DEVELOPMENT BEST PRACTICES WITH MICROSOFT STACK & ANGULAR

Cyber Matters

Bite-size insight on Cyber Security for the not too technical.

Guru N Guns's

OneSolution To dOTnET.

Johnny Zraiby

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

%d bloggers like this: