/// <summary>
        /// Attempts to get the value associated with the specified key from the <see cref="T:ExitGames.Threading.SynchronizedDictionary`2"/>.
        /// </summary>
        /// <param name="key">The key of the value to get.</param>
        /// <param name="value">When this method returns true, value contains the object from the <see cref="T:ExitGames.Threading.SynchronizedDictionary`2"/>
        ///  with the specified key.</param>
        /// <returns>true if the key was found in the <see cref="T:ExitGames.Threading.SynchronizedDictionary`2"/>; otherwise, false.</returns>
        public bool TryGetValue(TKey key, out TValue value)
        {
            bool flag;

            using (ReadLock.Enter(readerWriterLock))
            {
                flag = dictionary.TryGetValue(key, out value);
            }
            return(flag);
        }
        /// <summary>
        /// Determines whether the <see cref="T:ExitGames.Threading.SynchronizedDictionary`2"/> contains the specified key.
        /// </summary>
        /// <param name="key">The key to locate.</param>
        /// <returns>True if the <see cref="T:ExitGames.Threading.SynchronizedDictionary`2"/> contains an element with the specified key;
        ///otherwise, false.</returns>
        public bool ContainsKey(TKey key)
        {
            bool flag;

            using (ReadLock.Enter(readerWriterLock))
            {
                flag = dictionary.ContainsKey(key);
            }
            return(flag);
        }
示例#3
0
        /// <summary>
        ///  Gets the value associated with the specified key.
        /// </summary>
        /// <param name="key"> The key of the value to get. </param>
        /// <param name="value"> When this method returns, contains the value associated with the specified key, if the key is found;
        ///  otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.</param>
        /// <returns>True if an element with the specified key was found; otherwise, false.</returns>
        /// <exception cref="T:System.ArgumentNullException">
        ///     <paramref name="key"/> is null.
        ///  </exception>
        public bool Exists(TKey key, out TValue value)
        {
            bool flag;

            using (ReadLock.Enter(readerWriterLock))
            {
                flag = items.TryGetValue(key, out value);
            }
            return(flag);
        }
 /// <summary>
 /// Gets or sets the value associated with the specified key.
 /// </summary>
 /// <param name="key">The key of the value to get or set.</param>
 /// <returns>The value for the key.</returns>
 public TValue this[TKey key]
 {
     get
     {
         TValue local;
         using (ReadLock.Enter(readerWriterLock))
         {
             local = dictionary[key];
         }
         return(local);
     }
     set
     {
         using (WriteLock.Enter(readerWriterLock))
         {
             dictionary[key] = value;
         }
     }
 }
示例#5
0
        /// <summary>
        /// Gets the value associated with the specified key.
        /// If the key does not exist in the dictionary a value is loaded with the <see cref="M:ExitGames.Threading.SimpleBaseFactory`2.CreateItem(`0)"/> method.
        /// </summary>
        /// <param name="key">  The key of the value to get.</param>
        /// <returns> The value.</returns>
        public TValue Get(TKey key)
        {
            TValue local;
            TValue local2;

            using (ReadLock.Enter(readerWriterLock))
            {
                if (items.TryGetValue(key, out local))
                {
                    return(local);
                }
            }
            using (ReadLock.Enter(readerWriterLock))
            {
                if (!items.TryGetValue(key, out local))
                {
                    local = CreateItem(key);
                    items.Add(key, local);
                }
                local2 = local;
            }
            return(local2);
        }
 /// <summary>
 /// Enters a critical read section. Exit the critical section by disposing the return value.
 /// </summary>
 /// <returns>A disposable read lock. </returns>
 /// <exception cref="T:ExitGames.Threading.LockTimeoutException">
 /// A read lock could not be obtained within the <see cref="P:ExitGames.Threading.SynchronizedSingletonFactory`2.LockTimeout"/>.
 /// </exception>
 protected IDisposable ReaderLock()
 {
     return(ReadLock.TryEnter(this.readerWriterLockSlim, this.lockTimeout));
 }