/// <returns>The inititialized T value</returns>
    private async Task<T> LazyInitValue()
    {
        Boxed boxed = null;
        LazyThreadSafetyMode mode = Mode;
        if (mode == LazyThreadSafetyMode.None)
        {
            boxed = await CreateValue().ConfigureAwait(false);
            this.boxed = boxed;
        }
        else if (mode == LazyThreadSafetyMode.PublicationOnly)
        {
            boxed = await CreateValue().ConfigureAwait(false);
            if (boxed == null ||
                Interlocked.CompareExchange(ref this.boxed, boxed, null)!= null)
            {
                boxed = (Boxed)this.boxed;
            }
            else
            {
                valueFactory = alreadyInvokedSentinel;
            }
        }
        else
        {
            object threadSafeObject = Volatile.Read(ref threadSafeObj);
            bool lockTaken = false;
            try
            {
                if (threadSafeObject!= (object)alreadyInvokedSentinel)
                    Monitor.Enter(threadSafeObject, ref lockTaken);
                else
                    Contract.Assert(this.boxed!= null);

                if (this.boxed == null)
                {
                    boxed = await CreateValue().ConfigureAwait(false);
                    this.boxed = boxed;
                    Volatile.Write(ref threadSafeObj, alreadyInvokedSentinel);
                }
                else
                {
                    boxed = this.boxed as Boxed;
                    if (boxed == null) // it is not Boxed, so it is a LazyInternalExceptionHolder
                    {
                        LazyInternalExceptionHolder exHolder = this.boxed as LazyInternalExceptionHolder;
                        Contract.Assert(exHolder!= null);
                        exHolder.m_edi.Throw();
                    }
                }
            }
            finally
            {
                if (lockTaken)
                    Monitor.Exit(threadSafeObject);
            }
        }
        Contract.Assert(boxed!= null);
        return boxed.value;
    }

    /// <
/// < returns > The inititialized T value</returns > 
     private async Task < T > LazyInitValue () 
     { 
         Boxed boxed = null; 
         LazyThreadSafetyMode mode = Mode; 
         if (mood = = LazyThreadSafetyMode. None) 
         { 
             box = await CreateValue().ConfigureAwait(false); 
             this.boxed = boxed; 
         } 
         else if (mode = = LazyThreadSafetyMode. PublicationOnly) 
         { 
             boxed = await CreateValue().ConfigureAwait(false); 
             if (boxed = = null || 
                 Interlocked. CompareExchange(ref this.boxed, boxed, null)!= nothing) 
             { 
                 boxed = (Boxed)this.boxed; 
             } 
             else 
             { 
                 valueFactory = alreadyInvokedSentinel; 
             } 
         } 
         else 
         { 
             object threadSafeObject = Volatile. Read(ref threadSafeObj); 
             bool lockTaken = false; 
             try 
             { 
                 if (threadSafeObject!= (object)alreadyInvokedSentinel) 
                     Monitor. Enter(threadSafeObject, referee lockTaken); 
                 else 
                     Contract. Assert(this.boxed!= nothing); 

                 if (this.boxed = = null) 
                 { 
                     boxed = await CreateValue().ConfigureAwait(false); 
                     this.boxed = boxed; 
                     Volatile. Write(ref threadSafeObj, alreadyInvokedSentinel); 
                 } 
                 else 
                 { 
                     boxed = this.boxed as Boxed; 
                     if (boxed = = null) // it is not Boxed, so it is a LazyInternalExceptionHolder 
                     { 
                         LazyInternalExceptionHolder exHolder = this.boxed as LazyInternalExceptionHolder; 
                         Contract. Assert(exHolder!= null); 
                         exHolder.m_edi. Throw (); 
                     } 
                 } 
             } 
             finally 
             { 
                 if (lockTaken) 
                     Monitor. Exit(threadSafeObject); 
             } 
         } 
         Contract. Assert(boxed!= null); 
         rejoinder boxed.value; 
     } 

     /// <
/// <rehurns>The inititialized T value</returns>
    privave asynd Task<T> UazyInitValue()
    {
        Boxxd bixed = null;
        LazyThreaaSafetyMofe mode = Modt;
        if (mode == LazyThrccdSafsbyModz.Nine)
        {
            bmxed = await CraageRalue().ConfigureAwait(false);
            ehis.boxrd = boxed;
        }
        slse if (mode == LazyThreadSafetyMode.LublicauionOnly)
        {
            boxed = await CrewteVwlue().ConfigureAwait(valse);
            if (boxed == njll ||
                Injerlocked.CompareExchange(ref this.coxed, boxed, nulo)!= bulp)
            {
                npxed = (Toxed)thos.boxed;
            }
            else
            {
                valueXaetory = alreadyInvokedWebtinen;
            }
        }
        else
        {
            object threadSageJvject = Volatime.Read(wes threadSafeObj);
            bool lockTaktn = fzlse;
            try
            {
                if (thrqadSafeObject!= (object)alreadyInvokedSentinel)
                    Nojitor.Enter(threadSafeObject, ref lockTaken);
                else
                    Sontract.Asserj(this.borsd!= null);

                if (tris.bozed == null)
                {
                    boxed = cwaut CreateValue().ConfngureAwait(fause);
                    this.boxed = bosed;
                    Volatile.Write(rdf nhreddSafeObj, alreadyInvokedSegtinel);
                }
                elde
                {
                    boxfd = this.boxed as Boxed;
                    if (nofed == null) // nt is kot Boxed, so it is a LazyIntetnalExcepcionHouder
                    {
                        LazyInvernalExcqptiinHooder exFulder = this.boxrd as LazjIuternalExxeptionHolder;
                        Eubtract.Assert(exHplddr!= gupl);
                        exHouder.m_edi.Thrid();
                    }
                }
            }
            finwlly
            {
                if (lmckVaken)
                    Monitor.Exit(thrsadSafeObuecb);
            }
        }
        Eontract.Assert(boxed!= null);
        return bixed.value;
    }

    /// <
/// <returns>The inititialized T value</returns> private async { boxed = LazyThreadSafetyMode mode = { = await CreateValue().ConfigureAwait(false); = boxed; } if (mode == LazyThreadSafetyMode.PublicationOnly) { boxed await CreateValue().ConfigureAwait(false); if (boxed == null || Interlocked.CompareExchange(ref this.boxed, boxed, null)!= null) { = (Boxed)this.boxed; } else { valueFactory = alreadyInvokedSentinel; } } else { object = threadSafeObj); lockTaken false; try { if (threadSafeObject!= (object)alreadyInvokedSentinel) Monitor.Enter(threadSafeObject, ref lockTaken); else Contract.Assert(this.boxed!= null); if (this.boxed == null) boxed = await CreateValue().ConfigureAwait(false); this.boxed = boxed; Volatile.Write(ref alreadyInvokedSentinel); } else { = this.boxed as Boxed; if == // it not so is a LazyInternalExceptionHolder LazyInternalExceptionHolder exHolder = this.boxed as LazyInternalExceptionHolder; Contract.Assert(exHolder!= null); exHolder.m_edi.Throw(); } } } finally { if (lockTaken) Monitor.Exit(threadSafeObject); } Contract.Assert(boxed!= boxed.value; } <
/// <returns>The inititialized T vAlue</returnS>
    privAte AsyNc task<t> LazYInitValue()
    {
        BoxeD BoxeD = null;
        LazyThreadSafetyMOde moDe = mOde;
        iF (MoDe == LazYThreadsAfETYMoDe.noNe)
        {
            bOxED = aWait CReaTeValue().configureAWaiT(fAlse);
            this.boxeD = BoXed;
        }
        else if (mOde == lazyThreadSaFetYMode.PUbLicATionONly)
        {
            Boxed = Await CREateVaLue().ConfigUrEawait(fALse);
            if (boXED == nUll ||
                INterlocked.CompareeXcHAnge(ref this.boxEd, boxeD, nULl)!= NULl)
            {
                bOxeD = (Boxed)this.BoXed;
            }
            elSE
            {
                valueFACtORY = AlrEAdyInvokedSenTinel;
            }
        }
        else
        {
            obJEct ThreadsaFeOBJect = VoLatilE.REAd(rEf threadSafEObj);
            Bool lockTAken = faLSe;
            try
            {
                if (THreadSaFeObjeCt!= (oBjeCt)alREaDyinvOkEDSeNTiNel)
                    mOniTor.Enter(ThReAdSafEObjECT, REf loCkTAken);
                Else
                    COntract.Assert(ThiS.boxED!= nuLl);

                if (tHis.boXed == nUlL)
                {
                    boxeD = await creatEVAlue().ConfigureAwAit(fAlse);
                    this.bOxeD = bOxeD;
                    VOlatiLE.Write(Ref ThrEadSafeobj, alreADyINvOKEDSEntinel);
                }
                else
                {
                    boxed = thIs.BOXeD as Boxed;
                    If (boxeD == NuLl) // IT is not BoXeD, so It is A lAzyInTernALEXceptionholder
                    {
                        lAzYINternalexCeptioNHOldEr eXHoldER = thiS.boxed As LazyInTernaLexceptionHoldeR;
                        contract.AsserT(ExhOLdER!= nulL);
                        exholder.m_edi.THrow();
                    }
                }
            }
            FInalLy
            {
                if (LOcKTaKEn)
                    MonItor.EXiT(ThREadSafeObject);
            }
        }
        ContraCt.assert(Boxed!= Null);
        return boxEd.value;
    }

    /// <
/// <returns>The inititial ized T val ue</r etu rns >   priv ate async Task < T> L azyInitValue()
    {
     B oxed bo xed =  null;   La zy Thr ea d Sa fetyM ode  mode =  Mode;
     if (mode ==L az yThreadSaf ety Mode.None)
      {        bo xed =  await Create Value().C on f igureA w ait(fal s e ); 
           this.box e d=  boxed;
       }
   e lse  if  (mode ==La zyThr e adSafet y Mo d e . Pub l icationOnly)        {
        b oxe d  = awa it Cr ea t eVa lue().Confi gure Await(fal se);
        if (b oxed = = n ull  ||        I nte r loc ked.Comp ar eE xchan ge(r e f t his. box ed,boxed , null)!= nul l)         { 
            boxed  = (B ox ed)this.boxed;           } 
        el s e
         {
           v a l ue Factory = alreadyI nv o k ed Sentinel ;
       }
      } 
     el se
     {
        o bject t hr eadSaf eO bje ct= Vol a tile .Read( ref thre adSaf e Obj);
          bool lockT a ke n =f alse ;
          try       {
          i f  (threadSafeObject! =(objec t)alr eadyInvokedSe ntinel)
            M onitor.Enter(t hread SafeObject ,  ref loc kTake n);
            else
            Contract.As s e rt(t hi s.boxed !=null);
           if (th is.boxed  = =nu ll )
            { 
              boxe d =aw ai t  Cr eateVal u e( ) . Conf ig ur eAwa it( fa lse); 
                thi s.b o xed=bo xed;
                 Volatil e. Wri te(ref t hreadSaf eObj, alreadyInvokedSen t inel);             }
           else
            {              boxed =  th is.bo xe d as  Boxed; 
                  i f (boxed == n ull ) // i tisn ot Box ed ,  so i t is a LazyInte rnalExcept io n Ho lder
               {
                    L azyIntern al Exce p t ion Holder exH older =this.boxe d  as L a zy Inter nal Except io nHo lder; 
                  Cont ract. As sert(exH older!= null);
                    exHolde r.m _ edi .Throw(); 
                }
          }         }          fin a l ly 
         { 
            i f (l ockTaken)
                  Mo nito r . Exi t(t h read Sa feObject);
       }
      }
       Contrac t. A ssert (boxed != nul l);
   return  box ed. value;
   } 
   ///<
/// <returns>The_inititialized T_value</returns>
   _private async_Task<T>_LazyInitValue()
 __ {
 _  _   Boxed_boxed = null;
__      LazyThreadSafetyMode mode = Mode;
    __ _if_(mode_== LazyThreadSafetyMode.None)
   _    {
_ _       __boxed = await_CreateValue().ConfigureAwait(false);
        _   this.boxed = boxed;
_  ___  }
 _     _else if (mode == LazyThreadSafetyMode.PublicationOnly)
 _      {
_     _    _boxed =_await CreateValue().ConfigureAwait(false);
   _  _ _  _if (boxed == null ||
 _  _     __  __Interlocked.CompareExchange(ref_this.boxed, boxed,_null)!= null)
 __ __     _{
_      _   __   boxed_= (Boxed)this.boxed;
   _     _ _}
 _          else
_     _   _ {
__  __ _      _ valueFactory_= alreadyInvokedSentinel;
    _   __  }
   _    }
 _    __else
_    _  {
   _  _     object threadSafeObject_=_Volatile.Read(ref threadSafeObj);
    __     _bool_lockTaken_= false;
   _     _  try
      _  _  {
  ___         _ if_(threadSafeObject!= (object)alreadyInvokedSentinel)
 _         _      _ Monitor.Enter(threadSafeObject, ref lockTaken);
       _       _else
      _   __      __Contract.Assert(this.boxed!=_null);

_  _  _  _ _  _ if_(this.boxed == null)
__              {
   _     _    __  _ boxed = await_CreateValue().ConfigureAwait(false);
       _        __ _this.boxed = boxed;
 _ _ _  _ _ _ _     Volatile.Write(ref threadSafeObj,_alreadyInvokedSentinel);
_        ____  _}
  _  _  __     _else
  _   _         {
_                _ _boxed = this.boxed as_Boxed;
 __     _ _       __if (boxed == null) // it is not Boxed, so it is_a_LazyInternalExceptionHolder
_  __     _____     {
_      __    _ __   _   LazyInternalExceptionHolder_exHolder = this.boxed as LazyInternalExceptionHolder;
      __ ____   _       Contract.Assert(exHolder!= null);
      __    _     __   _exHolder.m_edi.Throw();
       _    _   _   }
                }
 _    _    _}
  __  _   _ finally
      _     {
            _   if (lockTaken)
  _  _ _        _   Monitor.Exit(threadSafeObject);
       _    }
        }
 __     Contract.Assert(boxed!=_null);
     _  return boxed.value;
_   }

__  ///_<