In the beginning of my methods that handle the calls from outside, I run this method to make sure that everything's OK, or let the caller know what's wrong:
private static void Validate(Guid userId, EntityState state, object data)
{
if (userId == Guid.Empty)
throw new Exception("Token unrecognized!");
if (state == EntityState.Detached)
throw new Exception("Action unrecognized!");
if (data == null)
throw new Exception("Data unrecognized!");
}
I was happy with the method until R# remarked that I'm declaring the variables without using them, except for pre-condition check. Well, it's true that I do. It's kind of the whole idea.
It bothers me that the tool remarks on it, because it feels like smarter people than me have put in the message there. However, turning it off isn't an option because that'd turn off even the checks for actually unnecessarily declared variables.
Should I refactor the code? How can I improve it?
id
parameter to beuserId
? Also, the question title should describe the task performed by the code (e.g. "Function to validate a GUID, an EntityState, and some data"). Alternatively, if you are asking a "What is best practice?" question about hypothetical/generic code rather than real concrete code, then it's not a Code Review, and would be better suited for Software Engineering. I think that your question could use a bit more contextual information about what these parameters represent and where their values come from. \$\endgroup\$EntityState
? What isdata
? The contextual information would help us give you better advice, because there isn't much to work with. \$\endgroup\$