Does anyone know why Microsoft didn't include a Clear() method or IsDirty property or something of the like to the Lazy< T > class in the .NET Framework 4.0? (Updated question below)
We have a homebrew type that we have been using since .NET 3.5 where I work that does the same thing as Lazy< T > class yet allows you to have the instance re-evaluate the Lazy Func. We would like to replace our class with the new .NET one but this Clear() or IsDirty mechanism doesn't exist.
Let me rephrase the original question based on comments. Is there a way to reinitialize the Lazy< T > Func method without reinstantiating the class? If not, is there a way to implement it as an extension method or is just just a bad pattern to follow in the first place?
Because it is impossible to make it thread-safe. Classes that guarantee that the programmer will shoot his leg off without any way to fix the problem don't belong in a framework. You are free to shoot your own leg off.
What you want to do isn't Lazy initialization, it's something else. That's why it isn't on the Lazy<T>
class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With