Variable consolidation/substitution

I don't know if this is really feasible or even that much of a useful feature, but here goes;

I find, during code review, it's quite common for me to find code similar to below (crap example, but you get the idea);

int id = (int)p.Tag;
Logger.Log("ID: {0}", id);

Which I'll usually (99% of the time) change to this;

Logger.Log("ID: {0}", (int)p.Tag);

I just find it cleaner and obviously there's no other use for the id variable, there's no null checks before using it, etc.

So finally, my question.

Is is possible and/or worthwhile to turn this process into a Re# function?

Perhaps underline the id variable in it's usage and advise that it can be substituted for the assignment.

1 comment
Comment actions Permalink

Assuming the Log method takes an array of objects, your second code block should be:

Logger.Log("ID: {0}", p.Tag);

There's no need to un-box the variable if you're only going to box it again to pass as an object.


Please sign in to leave a comment.