Question

I was wondering either it is possible to create a rule in C# inside the code, that will prevent from "compiling" and print an error message of my choice. For example:

Let's say:

  • I have a method that takes as an argument bytes vector.
  • Inside that method I check what's the length of this byte vector.
  • If it's too long, to short etc I would like to prevent the program from compiling and print an error message in the Error list.

I know I could use assertion and stuff, but that is working on already compiled code.

Was it helpful?

Solution

I would answer NO because the compiler (at compilation time) can't know the value of the parameter at run time.

Have a nice day,

Alberto

EDIT: Check the first comment to your question because it's a more complete answer compared to this one :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top