Beispiel #1
0
        private static RiotUser SearchUserByOption(object value, RiotUserSearchOption option)
        {
            RiotUser foundUser = null;

            lock (mUsers)
            {
                switch (option)
                {
                case RiotUserSearchOption.Id:
                    foundUser = mUsers.Find(x => x.Id == value.ToString());
                    break;

                case RiotUserSearchOption.Puuid:
                    foundUser = mUsers.Find(x => x.Puuid == value.ToString());
                    break;

                case RiotUserSearchOption.AccountId:
                    foundUser = mUsers.Find(x => x.AccountId == value.ToString());
                    break;

                case RiotUserSearchOption.Name:
                    foundUser = mUsers.Find(x => x.Name == value.ToString());
                    break;

                default:
                    throw new ArgumentException($"UserManager.SearchUserByOption - This option is not supported. Option:{option}");
                }
            }

            return(foundUser);
        }
Beispiel #2
0
        public static RiotUser GetUser(object value, RiotUserSearchOption option)
        {
            CheckValueTypeByOption(value, option);

            RiotUser foundUser = SearchUserByOption(value, option);

            if (foundUser == null)
            {
                throw new WebResponseException((int)WebResponseStatusCode.NotFound, $"UserManager.GetUser - Not Found User. Value:{value}, Option:{option}");
            }

            return(foundUser);
        }
Beispiel #3
0
        private static void CheckValueTypeByOption(object value, RiotUserSearchOption option)
        {
            TypeCode code = Type.GetTypeCode(value.GetType());

            switch (option)
            {
            case RiotUserSearchOption.Id:
            case RiotUserSearchOption.Puuid:
            case RiotUserSearchOption.AccountId:
            case RiotUserSearchOption.Name:
                if (code != TypeCode.String)
                {
                    throw new ArgumentException($"UserManager.CheckValueByOption - The value type matching this option is string. Value:{code} Option:{option}");
                }

                break;

            default:
                throw new ArgumentException($"UserManager.CheckValueByOption - This option is not supported. Option:{option}");
            }
        }