コード例 #1
0
        public Task InvokeFiltersAsync <TContext, TFilter>(TContext context)
            where TContext : IFilterContext
            where TFilter : ICommandFilter
        {
            var filterType = typeof(TFilter);

            if (_cachedDelegates.TryGetValue(filterType, out var proccessDelegate))
            {
                return(proccessDelegate(context));
            }

            IFilterFactory selectedFilterFactory = null;

            foreach (var filterFactory in _filterFactories)
            {
                if (filterFactory.CanInvoke(filterType))
                {
                    selectedFilterFactory = filterFactory;
                    break;
                }
            }

            if (selectedFilterFactory.HasNoContent())
            {
                return(Task.CompletedTask);
            }

            var filterDelegate = selectedFilterFactory.GetFiltersDelegate();

            CheckFilterDelegate(selectedFilterFactory, filterDelegate);

            var buildedDelegate = BuildDelegate(filterType, filterDelegate);

            return(buildedDelegate(context));
        }