public void AnalyzeConfigureMethod(OperationBlockStartAnalysisContext context) { var configureMethod = (IMethodSymbol)context.OwningSymbol; var middleware = ImmutableArray.CreateBuilder <MiddlewareItem>(); // Note: this is a simple source-order implementation. We don't attempt perform data flow // analysis in order to determine the actual order in which middleware are ordered. // // This can currently be confused by things like Map(...) context.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 == _context.StartupSymbols.IApplicationBuilder) { middleware.Add(new MiddlewareItem(invocation)); } }, OperationKind.Invocation); context.RegisterOperationBlockEndAction(context => { _context.ReportAnalysis(new MiddlewareAnalysis(context.Compilation, configureMethod, middleware.ToImmutable())); }); }
public void AnalyzeConfigureServices(OperationBlockStartAnalysisContext context) { var configureServicesMethod = (IMethodSymbol)context.OwningSymbol; var options = ImmutableArray.CreateBuilder <OptionsItem>(); context.RegisterOperationAction(context => { if (context.Operation is ISimpleAssignmentOperation operation && operation.Value.ConstantValue.HasValue && operation.Target is IPropertyReferenceOperation property && property.Property?.ContainingType?.Name != null && property.Property.ContainingType.Name.EndsWith("Options")) { options.Add(new OptionsItem(property.Property, operation.Value.ConstantValue.Value)); } }, OperationKind.SimpleAssignment); context.RegisterOperationBlockEndAction(context => { _context.ReportAnalysis(new OptionsAnalysis(configureServicesMethod, options.ToImmutable())); }); }
public void AnalyzeConfigureServices(OperationBlockStartAnalysisContext context) { var configureServicesMethod = (IMethodSymbol)context.OwningSymbol; var services = ImmutableArray.CreateBuilder <ServicesItem>(); context.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 == _context.StartupSymbols.IServiceCollection) { services.Add(new ServicesItem(invocation)); } }, OperationKind.Invocation); context.RegisterOperationBlockEndAction(context => { _context.ReportAnalysis(new ServicesAnalysis(configureServicesMethod, services.ToImmutable())); }); }