コード例 #1
0
 /// <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();
         }
     }
 }
コード例 #2
0
        /// <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);
                }
            }
        }
コード例 #3
0
        public TAttribute GetControllerAttribute <TAttribute>() where TAttribute : Attribute
        {
            var attribute = ControllerType.GetTypeInfo().GetCustomAttribute(typeof(TAttribute));

            return(attribute == null ? null : (TAttribute)attribute);
        }