Is there any way to to add custom compile time errors when there is a mismatch in number of arguments passed to String.Format in C#
Eg:
String.Format("{0} and {1} are my pets", animal);
the above line should throw an error since we have passed only one argument "animal"
, while it is expecting two {0},{1}
.. but in reality it throws just run time errors.
FxCop / Code Analysis will pick this up. And yes, you can do that at compile time in VS Premium / Ultimate.
Resharper will add an IDE warning for that. However, that isn't a compiler error; what you have written is perfectly fine as far as the compiler is concerned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With