/// <summary> /// Initializes this instance. /// </summary> public void Init() { if (Filters == null) { var attributes = ControllerType.GetTypeInfo().GetCustomAttributes().ToArray(); var apiFilters = attributes .Where(x => typeof(IApiFilter).IsAssignableFrom(x.GetType())) .Cast <IApiFilter>() .ToArray(); var asyncFilters = attributes .Where(x => typeof(IApiFilterAsync).IsAssignableFrom(x.GetType())) .Cast <IApiFilterAsync>() .ToArray(); var policyFilters = attributes .Where(x => typeof(IPolicyApiFilter).IsAssignableFrom(x.GetType())) .Cast <IPolicyApiFilter>() .ToArray(); Filters = apiFilters.Select(x => new ApiFilterWrapper(x)) .Union(asyncFilters.Select(x => new ApiFilterWrapper(x))) .Union(policyFilters.Select(x => new ApiFilterWrapper(x, () => AuthPolicyStore))) .ToArray(); foreach (var action in Actions) { action.Init(); } } }
/// <summary> /// Initializes the specified options retriver. /// </summary> /// <param name="optionsRetriver">The options retriever.</param> /// <exception cref="ArgumentNullException">optionsRetriver</exception> internal void Init(ILiteApiOptionsAccessor optionsRetriver) { if (optionsRetriver == null) { throw new ArgumentNullException(nameof(optionsRetriver)); } if (Filters == null) { var attributes = ControllerType.GetTypeInfo().GetCustomAttributes().ToArray(); var apiFilters = attributes .Where(x => typeof(IApiFilter).IsAssignableFrom(x.GetType())) .Cast <IApiFilter>() .ToArray(); var asyncFilters = attributes .Where(x => typeof(IApiFilterAsync).IsAssignableFrom(x.GetType())) .Cast <IApiFilterAsync>() .ToArray(); var policyFilters = attributes .Where(x => typeof(IPolicyApiFilter).IsAssignableFrom(x.GetType())) .Cast <IPolicyApiFilter>() .ToArray(); Filters = apiFilters.Select(x => new ApiFilterWrapper(x)) .Union(asyncFilters.Select(x => new ApiFilterWrapper(x))) .Union(policyFilters.Select(x => new ApiFilterWrapper(x, () => optionsRetriver.GetOptions().AuthorizationPolicyStore))) .ToArray(); DateTimeParsingFormat = ( attributes .FirstOrDefault(x => x is DateTimeParsingFormatAttribute) as DateTimeParsingFormatAttribute )?.ParsingFormat; foreach (var action in Actions) { action.Init(optionsRetriver); } } }
public TAttribute GetControllerAttribute <TAttribute>() where TAttribute : Attribute { var attribute = ControllerType.GetTypeInfo().GetCustomAttribute(typeof(TAttribute)); return(attribute == null ? null : (TAttribute)attribute); }