private bool ThreadSafeEvaluate() { if (base.valueFactory != null) { using (base.Sync.UseLock()) { if (base.valueFactory != null) { try { this.value = ((Func <TArg, T>)base.valueFactory)(this.arg); } catch (Exception exception) { this.value = default(T); this.errorData = new ResultErrorData(exception, true); } this.arg = default(TArg); base.valueFactory = null; return(true); } } } return(false); }
private bool ThreadSafeEvaluate(bool throwOnError, out T value) { if (this.valueFactory != null) { lock (result) { if (this.valueFactory != null) { try { value = this.valueFactory(this.arg); this.valueFactoryReturnedNull = ((T)value) == null; base.weakValue = new WeakReferenceT <T>(value); } catch (Exception exception) { value = default(T); base.weakValue = null; this.errorData = new ResultErrorData(exception, !throwOnError); } finally { this.arg = default(TArg); this.valueFactory = null; } return(true); } } } value = default(T); return(false); }
public LazyResult(Func <TArg, T> valueFactory, TArg arg, LazyThreadSafetyMode lazyThreadSafetyMode, CriticalSection sync) : base(sync) { Validate.IsNotNull <Func <TArg, T> >(valueFactory, "valueFactory"); if (lazyThreadSafetyMode == LazyThreadSafetyMode.PublicationOnly) { throw new ArgumentException("LazyThreadSafetyMode.PublicationOnly is not supported", "lazyThreadSafetyMode"); } if ((lazyThreadSafetyMode != LazyThreadSafetyMode.None) && (lazyThreadSafetyMode != LazyThreadSafetyMode.ExecutionAndPublication)) { ExceptionUtil.ThrowInvalidEnumArgumentException <LazyThreadSafetyMode>(lazyThreadSafetyMode, "lazyThreadSafetyMode"); } base.valueFactory = valueFactory; this.arg = arg; base.lazyThreadSafetyMode = lazyThreadSafetyMode; this.value = default(T); this.errorData = null; }
private bool UnsafeEvaluate() { if (base.valueFactory == null) { return(false); } try { this.value = ((Func <TArg, T>)base.valueFactory)(this.arg); } catch (Exception exception) { this.value = default(T); this.errorData = new ResultErrorData(exception, true); } this.arg = default(TArg); base.valueFactory = null; return(true); }
internal ResultError(ResultErrorData data) { this.data = data; }