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); }
private void AnalyzeStartupMethods(OperationBlockStartAnalysisContext context, StartupSymbols symbols, ConcurrentBag <StartupComputedAnalysis> analyses) { if (!IsStartupFile(context)) { return; } if (context.OwningSymbol.Kind != SymbolKind.Method) { return; } var startupAnalysisContext = new StartupAnalysisContext(context, symbols); var method = (IMethodSymbol)context.OwningSymbol; if (StartupFacts.IsConfigureServices(symbols, method)) { for (var i = 0; i < ConfigureServicesMethodAnalysisFactories.Length; i++) { var analysis = ConfigureServicesMethodAnalysisFactories[i].Invoke(startupAnalysisContext); analyses.Add(analysis); OnAnalysisStarted(analysis); } OnConfigureServicesMethodFound(method); } if (StartupFacts.IsConfigure(symbols, method)) { for (var i = 0; i < ConfigureMethodAnalysisFactories.Length; i++) { var analysis = ConfigureMethodAnalysisFactories[i].Invoke(startupAnalysisContext); analyses.Add(analysis); OnAnalysisStarted(analysis); } OnConfigureMethodFound(method); } }
public static MvcOptionsAnalysis CreateAndInitialize(StartupAnalysisContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var analysis = new MvcOptionsAnalysis((IMethodSymbol)context.OperationBlockStartAnalysisContext.OwningSymbol); context.OperationBlockStartAnalysisContext.RegisterOperationAction(context => { if (context.Operation is ISimpleAssignmentOperation operation && operation.Value.ConstantValue.HasValue && operation.Target is IPropertyReferenceOperation property && property.Member?.Name == SymbolNames.EnableEndpointRoutingProperty) { analysis.EndpointRoutingEnabled = operation.Value.ConstantValue.Value as bool?; } }, OperationKind.SimpleAssignment); return(analysis); }