示例#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);
 }
示例#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);
 }
示例#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;
 }
示例#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);
 }
示例#5
0
 internal ResultError(ResultErrorData data)
 {
     this.data = data;
 }