If I have a Lazy value defined such as
Lazy<MyObject> _lazyObject = new Lazy<MyObject>();
if (_lazyObject.IsValueCreated && _lazyObject.Value.Handle == IntPtr.Zero)
return _lazyObject?.Value?.MyMethod() ?? false;
From the question it is unclear what the problem is you're actually trying to solve.
_lazyObject.Value should never be null unless you're providing a factory into the constructor that returns null.
var lazy = new Lazy<string>(() => null); var isNull = lazy.Value == null; // isNull is true
Lazy<> is being used correctly you shouldn't need to check for null, you just use the value and whatever thread gets there first creates the value. Checking
IsValueCreated will tell you if the value has been created yet, but I don't know why you would need to know this.
Generally the field/property holding the
Lazy<> should be made
readonly as you don't want to have multiple instances.