Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing warning when function result is not assigned to variable

Tags:

function

c#

I have a function that returns a modified copy of the object that was passed to this function. I often do something like this:

obj = obj.Foo(param);

Don't ask why, I simply have to. But sometimes, I (and others) forgot to assign the return value, doing this:

obj.Foo(param);

which repeatedly leads to time-consuming debugging.

Is there any way to show a warning or error every time when the function result is not assigned to a variable? Or any other suggestions on how to solve this issue?

like image 633
Grzes Avatar asked Aug 02 '11 13:08

Grzes


1 Answers

You could use an out parameter, so the call would look like this:

obj.Foo(param, out obj);
like image 106
Henrik Avatar answered Nov 15 '22 08:11

Henrik