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);
        }
Exemple #2
0
 internal static void OnMiddlewareAnalysisCompleted(MiddlewareAnalysis analysis)
 {
     MiddlewareAnalysisCompleted?.Invoke(null, analysis);
 }
Exemple #3
0
 internal void OnMiddlewareAnalysisCompleted(MiddlewareAnalysis analysis)
 {
     MiddlewareAnalysisCompleted?.Invoke(this, analysis);
     StartupAnalyzerEventSink.OnMiddlewareAnalysisCompleted(analysis);
 }
 public void ReportAnalysis(MiddlewareAnalysis analysis)
 {
     ReportAnalysisCore(analysis.StartupType, analysis);
     _analyzer.OnMiddlewareAnalysisCompleted(analysis);
 }
Exemple #5
0
 internal void OnMiddlewareAnalysisCompleted(MiddlewareAnalysis analysis)
 {
     MiddlewareAnalysisCompleted?.Invoke(this, analysis);
 }