Beispiel #1
0
 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);
 }
Beispiel #2
0
 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);
 }
Beispiel #3
0
 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;
 }
Beispiel #4
0
 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);
 }
Beispiel #5
0
 internal ResultError(ResultErrorData data)
 {
     this.data = data;
 }