Several methods in our code base use MaybeObject, which can be passed to functions when the result can be known, or can rely on an external call to a web service that has not yet been executed. For example, the property below can either have the specified known value, or not specify and call after the asynchronous call is completed, it will return the result of the Async call.
private string _internalString; public string stringProp { get { if (!string.IsNullOrEmpty(_internalString)) return _internalString; return resultOfAsyncCallFromSomewhereElse; } set { _internalString = value; } }
Obviously, trying to reference a property before ending the asynchronous call will result in the null reference being thrown out, so we also have a flag to check if this value is available.
The question is, in the code below, would it be creating a lambda attempt and evaluating stringProp (which has not yet been filled), or will the evaluation be postponed until the resulting action is called (which will complete the asynchronous operation after verification)?
public Action ExampleMethod(MaybeObject maybe) { return () => doSomethingWithString(maybe.stringProp); }
mavnn
source share