fCraft.PlayerDB.GetReadLock C# (CSharp) Method

GetReadLock() public static method

public static GetReadLock ( ) : ReadLockHelper
return ReadLockHelper
        public static ReadLockHelper GetReadLock() {
            return new ReadLockHelper( SyncRoot );
        }

Usage Example

        /// <summary> Finds player by name pattern. </summary>
        /// <param name="pattern"> Pattern to search for.
        /// Asterisk (*) matches zero or more characters.
        /// Question mark (?) matches exactly one character. </param>
        /// <param name="limit"> Maximum number of results to return. </param>
        /// <returns> A sequence of zero or more PlayerInfos whose names match the pattern. </returns>
        public IEnumerable <PlayerInfo> FindByPattern(string pattern, int limit)
        {
            if (pattern == null)
            {
                throw new ArgumentNullException("pattern");
            }
            string            regexString = "^" + RegexNonNameChars.Replace(pattern, "").Replace("*", ".*").Replace("?", ".") + "$";
            Regex             regex       = new Regex(regexString, RegexOptions.IgnoreCase);
            List <PlayerInfo> result      = new List <PlayerInfo>();

            using (PlayerDB.GetReadLock()) {
                int total = PlayerDB.List.Count;
                for (int i = 0; i < total; i++)
                {
                    if (regex.IsMatch(PlayerDB.List[i].Name))
                    {
                        result.Add(PlayerDB.List[i]);
                        if (result.Count >= limit)
                        {
                            break;
                        }
                    }
                }
            }
            return(result.ToArray());
        }
All Usage Examples Of fCraft.PlayerDB::GetReadLock