コード例 #1
0
ファイル: NewLazy.cs プロジェクト: ingted/fsharpadvent2016
        public Lazy(SerializationInfo information, StreamingContext context)
        {
            var boxed = (Boxed)information.GetValue("m_boxed", typeof(Boxed));

            m_value          = boxed.m_value;
            m_implementation = null;
        }
コード例 #2
0
ファイル: NewLazy.cs プロジェクト: ingted/fsharpadvent2016
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Threading.Lazy{T}"/> class
        /// that uses a specified initialization function and a specified thread-safety mode.
        /// </summary>
        /// <param name="valueFactory">
        /// The <see cref="T:System.Func{T}"/> invoked to produce the lazily-initialized value when it is needed.
        /// </param>
        /// <param name="mode">The lazy thread-safety mode.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="valueFactory"/> is
        /// a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="mode"/> mode contains an invalid value.</exception>
        public Lazy(Func <T> valueFactory, LazyThreadSafetyMode mode)
        {
            if (valueFactory == null)
            {
                throw new ArgumentNullException(nameof(valueFactory));
            }

            m_implementation = CreateInitializerFromMode(mode, this, valueFactory);
        }
コード例 #3
0
ファイル: NewLazy.cs プロジェクト: ingted/fsharpadvent2016
        /// <summary>
        /// Creates the underlying value using the factory object into a helper object and, for the
        /// first object to complete its factory, uses that objects ILazyItem implementation
        /// </summary>
        /// <param name="factory">The object factory used to create the underlying object</param>
        /// <param name="comparand">The publication object, used for synchronisation and comparison</param>
        /// <returns>The underlying object</returns>
        private T CreateValuePublicationOnly(Func <T> factory, PublicationOnly comparand)
        {
            var possibleValue = factory();

            lock (comparand)
            {
                if (ReferenceEquals(m_implementation, comparand))
                {
                    m_value          = possibleValue;
                    m_implementation = null;
                }
            }
            return(m_value);
        }
コード例 #4
0
ファイル: NewLazy.cs プロジェクト: ingted/fsharpadvent2016
 /// <summary>
 /// Creates the underlying value using the factory object, placing the result inside this
 /// object, and then used the Lazy objects ILazyItem implemenation.to refer to it.
 /// </summary>
 /// <param name="factory">The object factory used to create the underlying object</param>
 /// <param name="forceMemoryBarrier">true when called with ExecutionAndPublication, false
 /// when called with None</param>
 /// <returns>The underlying object</returns>
 private T CreateValue(Func <T> factory, LazyThreadSafetyMode mode)
 {
     try
     {
         m_value          = factory();
         m_implementation = null;
         return(m_value);
     }
     catch (Exception exception) when(!ReferenceEquals(CreateInstance.Factory, factory))
     {
         m_implementation = new LazyException(exception, mode);
         throw;
     }
 }
コード例 #5
0
ファイル: NewLazy.cs プロジェクト: ingted/fsharpadvent2016
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.Threading.Lazy{T}"/> class that
 /// uses a pre-initialized specified value.
 /// </summary>
 /// <remarks>
 /// An instance created with this constructor should be usable by multiple threads
 //  concurrently.
 /// </remarks>
 public Lazy(T value)
 {
     m_value          = value;
     m_implementation = null;
 }