예제 #1
0
        public static MiddlewareAnalysis CreateAndInitialize(StartupAnalysisContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var symbols  = context.StartupSymbols;
            var analysis = new MiddlewareAnalysis((IMethodSymbol)context.OperationBlockStartAnalysisContext.OwningSymbol);

            var middleware = ImmutableArray.CreateBuilder <MiddlewareItem>();

            context.OperationBlockStartAnalysisContext.RegisterOperationAction(context =>
            {
                // We're looking for usage of extension methods, so we need to look at the 'this' parameter
                // rather than invocation.Instance.
                if (context.Operation is IInvocationOperation invocation &&
                    invocation.Instance == null &&
                    invocation.Arguments.Length >= 1 &&
                    invocation.Arguments[0].Parameter?.Type == symbols.IApplicationBuilder)
                {
                    middleware.Add(new MiddlewareItem(invocation));
                }
            }, OperationKind.Invocation);

            context.OperationBlockStartAnalysisContext.RegisterOperationBlockEndAction(context =>
            {
                analysis.Middleware = middleware.ToImmutable();
            });

            return(analysis);
        }
예제 #2
0
 internal static void OnMiddlewareAnalysisCompleted(MiddlewareAnalysis analysis)
 {
     MiddlewareAnalysisCompleted?.Invoke(null, analysis);
 }
예제 #3
0
 internal void OnMiddlewareAnalysisCompleted(MiddlewareAnalysis analysis)
 {
     MiddlewareAnalysisCompleted?.Invoke(this, analysis);
     StartupAnalyzerEventSink.OnMiddlewareAnalysisCompleted(analysis);
 }
예제 #4
0
 public void ReportAnalysis(MiddlewareAnalysis analysis)
 {
     ReportAnalysisCore(analysis.StartupType, analysis);
     _analyzer.OnMiddlewareAnalysisCompleted(analysis);
 }
예제 #5
0
 internal void OnMiddlewareAnalysisCompleted(MiddlewareAnalysis analysis)
 {
     MiddlewareAnalysisCompleted?.Invoke(this, analysis);
 }