I want to automatically remove all explicit types and exchange them with the var keyword in a big solution, e.g. instead of
int a = 1;
I want to have:
var a = 1;
This is just cosmetics, the code in the solution works perfectly fine, I just want to have things consistent, as I started out using explicit types, but later on used var-keywords.
I’m guessing I would have to write some sort of code parser – sounds a little cumbersome. Does anybody know an easy solution to this?
Cheers,
Chris
This isn’t an answer per se, but it’s too long for a comment.
You should strongly consider not doing this. There’s no stylistic concern with mixing explicit and inferential typing (you should infer types when you need to, either when using anonymous types or when it makes the code easier to read), and there are plenty of potential issues you’ll encounter with this:
nullare ineligibleI.E.
Obviously, this is a simple (and unlikely) example, but changing
foofromobjecttovarwould result infoobeing typed as astringinstead ofobject, and would change the semantics of the code (it wouldn’t even compile in this case, but you could easily run into more difficult to find scenarios where it changes overload resolution but doesn’t produce a compile-time error).In other words, don’t do this, please.