Пример #1
0
        public CheckerService([NotNull] IConfiguration configuration, [NotNull] IFactory factory, [NotNull] ITraceService trace, [NotNull, ItemNotNull, ImportMany] IEnumerable <IChecker> checkers)
        {
            Configuration = configuration;
            Factory       = factory;
            Trace         = trace;

            var list = new List <CheckerInfo>();

            foreach (var checker in checkers)
            {
                foreach (var method in checker.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance))
                {
                    if (method.GetCustomAttribute <CheckAttribute>() == null)
                    {
                        continue;
                    }

                    var checkerInfo = new CheckerInfo(method.DeclaringType.Name, method.Name, context =>
                    {
                        var parameters = new object[]
                        {
                            context
                        };

                        return(method.Invoke(checker, parameters) as IEnumerable <IDiagnostic>);
                    });

                    list.Add(checkerInfo);
                }
            }

            Checkers = list;
        }
Пример #2
0
        protected virtual void TraceDiagnostics([NotNull] ICheckerContext context, [NotNull] CheckerInfo checker, [NotNull, ItemNotNull] IDiagnostic[] diagnostics, bool treatWarningsAsErrors)
        {
            if (checker.Severity == CheckerSeverity.Default)
            {
                Trace.TraceDiagnostics(diagnostics, treatWarningsAsErrors);
                return;
            }

            var severity = Severity.Information;

            switch (checker.Severity)
            {
            case CheckerSeverity.Information:
                severity = Severity.Information;
                break;

            case CheckerSeverity.Warning:
                severity = Severity.Warning;
                break;

            case CheckerSeverity.Error:
                severity = Severity.Error;
                break;
            }

            Trace.TraceDiagnostics(diagnostics, severity, treatWarningsAsErrors);
        }