private TypeParserResolver BuildTypeParserResolver(ParameterInfo parameterInfo, TypeParserResolver defaultParserResolver) { var useParserAttribute = parameterInfo .GetCustomAttributes(inherit: false) .OfType <UseParserAttribute>() .FirstOrDefault(); return(UseParserAttribute.ToTypeParserResolver(useParserAttribute, defaultParserResolver)); }
private TypeParserResolver BuildTypeParserResolver(ControllerType controllerType, MethodInfo method) { var useParserAttribute = method .GetCustomAttributes(inherit: true) .OfType <UseParserAttribute>() .LastOrDefault(); return(UseParserAttribute.ToTypeParserResolver(useParserAttribute, controllerType.TypeParserResolver)); }
/// <summary> /// Returns a <see cref="TypeParserResolver"/> filled with the parsers from the <see cref="UseParserAttribute"/> attribute. /// </summary> /// <param name="useParser"></param> /// <param name="defaultResolver"></param> /// <returns></returns> public static TypeParserResolver ToTypeParserResolver(UseParserAttribute useParser, TypeParserResolver defaultResolver) { var result = defaultResolver; if (useParser?.IsValid ?? false) { result = result == null ? TypeParserResolverCache.Find(useParser.Parsers) : TypeParserResolverCache.Find(result.GetAugmentedParsers(useParser.Parsers)); } return(result); }
/// <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); }