Ejemplo n.º 1
0
        public static ServicesAnalysis CreateAndInitialize(StartupAnalysisContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

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

            var services = ImmutableArray.CreateBuilder <ServicesItem>();

            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.IServiceCollection)
                {
                    services.Add(new ServicesItem(invocation));
                }
            }, OperationKind.Invocation);

            context.OperationBlockStartAnalysisContext.RegisterOperationBlockEndAction(context =>
            {
                analysis.Services = services.ToImmutable();
            });

            return(analysis);
        }
Ejemplo n.º 2
0
 internal static void OnServicesAnalysisCompleted(ServicesAnalysis analysis)
 {
     ServicesAnalysisCompleted?.Invoke(null, analysis);
 }
Ejemplo n.º 3
0
 internal void OnServicesAnalysisCompleted(ServicesAnalysis analysis)
 {
     ServicesAnalysisCompleted?.Invoke(this, analysis);
     StartupAnalyzerEventSink.OnServicesAnalysisCompleted(analysis);
 }
Ejemplo n.º 4
0
 public void ReportAnalysis(ServicesAnalysis analysis)
 {
     ReportAnalysisCore(analysis.StartupType, analysis);
     _analyzer.OnServicesAnalysisCompleted(analysis);
 }
Ejemplo n.º 5
0
 internal void OnServicesAnalysisCompleted(ServicesAnalysis analysis)
 {
     ServicesAnalysisCompleted?.Invoke(this, analysis);
 }