Sorry, I deleted my comment and turned it into an answer. And then noticed that JaredPar said it better than me and deleted my answer. (For other's reference I was talking about the new() restriction.
–
RayFeb 3 '12 at 17:16

ThrowIfNull also has a race condition if you're changing it before calling OrNull. And if you wanted an exception you would get that anyway when you tried to operate on the null object.
–
RayFeb 3 '12 at 17:18

1

Oh and you could just have return obj ?? new T();
–
RayFeb 3 '12 at 17:19

thanks! I made an override with a bool for throwing. I was thinking a global setting would be useful for my own debugging purposes. I'm a beginner and was seeing this as kind of a personal crutch.
–
BenjaminFeb 3 '12 at 17:19

@Ray that is getting even shorter! I thought it was possible but I couldn't figure it out. Thanks again.
–
BenjaminFeb 3 '12 at 17:21

1

@Benjamin like Jared said, there's no way to know what this function does. Something somewhere else in the code might have set or unset the flag without your knowledge. If you want behaviour like that, put it in another argument and have an override with a default value.
–
SimonFeb 4 '12 at 8:11

David what do programmers mean by "default"? I see it often but haven't understood it yet. Does that refer to the result of a customized parameterless constructor? Whatever I establish as being the default? Or just an empty instance of the class? Thanks.
–
BenjaminFeb 3 '12 at 21:05