Exemple #1
0
        private TypeFormatterResolver BuildTypeFormatterResolver(ControllerType controllerType, MethodInfo method)
        {
            var useFormatterAttribute = method
                                        .GetCustomAttributes(inherit: true)
                                        .OfType <UseFormatterAttribute>()
                                        .LastOrDefault();

            return(UseFormatterAttribute.ToTypeFormatterResolver(useFormatterAttribute, controllerType.TypeFormatterResolver));
        }
Exemple #2
0
        /// <summary>
        /// Returns a <see cref="TypeParserResolver"/> filled with the parsers from the <see cref="UseParserAttribute"/> attribute.
        /// </summary>
        /// <param name="useFormatter"></param>
        /// <param name="defaultResolver"></param>
        /// <returns></returns>
        public static TypeFormatterResolver ToTypeFormatterResolver(UseFormatterAttribute useFormatter, TypeFormatterResolver defaultResolver)
        {
            var result = defaultResolver;

            if (useFormatter?.IsValid ?? false)
            {
                result = result == null
                    ? TypeFormatterResolverCache.Find(useFormatter.Formatters)
                    : TypeFormatterResolverCache.Find(result.GetAugmentedFormatters(useFormatter.Formatters));
            }

            return(result);
        }
Exemple #3
0
        /// <summary>
        /// Creates a new object.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="defaultParserResolver"></param>
        /// <param name="defaultFormatterResolver"></param>
        public ControllerType(Type type, TypeParserResolver defaultParserResolver, TypeFormatterResolver defaultFormatterResolver)
        {
            Type = type;

            FilterAttributes = Type.GetCustomAttributes(inherit: true)
                               .OfType <IFilterAttribute>()
                               .ToArray();

            var useParserAttr = Type.GetCustomAttributes(typeof(UseParserAttribute), inherit: true)
                                .OfType <UseParserAttribute>()
                                .FirstOrDefault();

            TypeParserResolver = UseParserAttribute.ToTypeParserResolver(useParserAttr, defaultParserResolver);

            var useFormatterAttr = Type.GetCustomAttributes(typeof(UseFormatterAttribute), inherit: true)
                                   .OfType <UseFormatterAttribute>()
                                   .FirstOrDefault();

            TypeFormatterResolver = UseFormatterAttribute.ToTypeFormatterResolver(useFormatterAttr, defaultFormatterResolver);
        }