예제 #1
0
        public static Client FindByUserName(string Input)
        {
            List <Client> Matches = new List <Client>();

            Client[] CachedList = AllClients.ToArray();
            //EXACT Match
            foreach (Client ThisClient in CachedList)
            {
                if (ThisClient.Username == Input)
                {
                    Matches.Add(ThisClient);
                }
            }
            if (Matches.Count > 0)
            {
                if (Matches.Count == 1)
                {
                    return(Matches[0]);
                }
                else
                {
                    return(NoClient);
                }
            }
            Matches.Clear();
            //Case Insensitive Match
            foreach (Client ThisClient in CachedList)
            {
                if (ThisClient.Username.ToUpperInvariant() == Input.ToUpperInvariant())
                {
                    Matches.Add(ThisClient);
                }
            }
            if (Matches.Count > 0)
            {
                if (Matches.Count == 1)
                {
                    return(Matches[0]);
                }
                else
                {
                    return(NoClient);
                }
            }
            Matches.Clear();
            //Contains Match...
            foreach (Client ThisClient in CachedList)
            {
                if (ThisClient.Username.ToUpperInvariant().Contains(Input.ToUpperInvariant()))
                {
                    Matches.Add(ThisClient);
                }
            }
            if (Matches.Count > 0)
            {
                if (Matches.Count == 1)
                {
                    return(Matches[0]);
                }
                else
                {
                    return(NoClient);
                }
            }
            Matches.Clear();
            //No match.
            return(NoClient);
        }