Пример #1
0
        /// <exception cref="AmbiguousMatchException">
        /// More than one of the requested attributes was found.
        /// </exception>
        /// <exception cref="TypeLoadException">
        /// A custom attribute type cannot be loaded.
        /// </exception>
        /// <exception cref="RiotGamesApiException">
        /// ParameterTypeAttribute not found
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="source" /> or <paramref name="predicate" /> is null.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// No element satisfies the condition in <paramref name="predicate" />.-or-The source
        /// sequence is empty.
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// <paramref name="element" /> is not a constructor, method, property, event, type, or field.
        /// </exception>
        public static Type GetParameterType(this LolParameterType enumVal)
        {
            var typeInfo = enumVal.GetType().GetTypeInfo();
            var v        = typeInfo.DeclaredMembers.First(x => x.Name == enumVal.ToString());
            var attr     = v.GetCustomAttribute <ParameterTypeAttribute>();

            if (attr == null)
            {
                throw new RiotGamesApiException("ParameterTypeAttribute not found");
            }
            return(attr.ParameterType);
        }
Пример #2
0
        /// <exception cref="AmbiguousMatchException">
        /// More than one of the requested attributes was found.
        /// </exception>
        /// <exception cref="RiotGamesApiException">
        /// ParameterTypeAttribute not found
        /// </exception>
        /// <exception cref="TypeLoadException">
        /// A custom attribute type cannot be loaded.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="source" /> or <paramref name="predicate" /> is null.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// No element satisfies the condition in <paramref name="predicate" />.-or-The source
        /// sequence is empty.
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// <paramref name="element" /> is not a constructor, method, property, event, type, or field.
        /// </exception>
        public static bool CompareParameterType(this LolParameterType enumVal, Type requestValueType)
        {
            var typeInfo = enumVal.GetType().GetTypeInfo();
            var v        = typeInfo.DeclaredMembers.First(x => x.Name == enumVal.ToString());
            var attr     = v.GetCustomAttribute <ParameterTypeAttribute>();

            if (attr == null)
            {
                throw new RiotGamesApiException("ParameterTypeAttribute not found");
            }
            var t1 = attr.ParameterType;
            var t2 = requestValueType;

            return(t1 == t2);
        }