Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value validation at compile/coding time

I was using Amazon SDK and notice this "warning":

enter image description here

How is it possible? I did not install any plugin or extension, I just install AWS SDK through Nuget. Is it a standard C#/Visual Studio feature?

like image 249
Luke Vo Avatar asked Dec 05 '16 05:12

Luke Vo


People also ask

Is Constexpr always evaluated at compile time?

A constexpr function that is eligible to be evaluated at compile-time will only be evaluated at compile-time if the return value is used where a constant expression is required. Otherwise, compile-time evaluation is not guaranteed.

What is checked at compile time?

Compile-time checking occurs during the compile time. Compile time errors are error occurred due to typing mistake, if we do not follow the proper syntax and semantics of any programming language then compile time errors are thrown by the compiler.

Is Const evaluated at compile time?

Constant expressions. Certain forms of expressions, called constant expressions, can be evaluated at compile time. In const contexts, these are the only allowed expressions, and are always evaluated at compile time.

What is compile time parameter?

Compile time parameters are parameters utilized during the compilation of a template. These parameters can only be used via the SparkleFormation library. It is for this reason that compile time parameters are generally discouraged from use.


1 Answers

Yes this is a feature that nuget packages can choose to leverage. These are sometimes called "code-aware libraries". They are nuget packages that ship with built-in roslyn analyzers. A discussion of how to write an analyzer is a some what extended topic. The magic is in the nuget's special analyzers folder:

Analyzers themselves are typically packaged and distributed as part of the NuGet packages that implement the API or library in question.

Microsoft has published several examples and walkthroughs in various places:

  • A walkthrough for the immutable collections library.
  • An example for a hypothetical RSS library is here.
like image 119
Mike Zboray Avatar answered Oct 19 '22 00:10

Mike Zboray