示例#1
0
        private static void ParseAllowedElement(XElement xElement, AnalyzerConfigBuilder configBuilder)
        {
            var allowedDependencyRule = ParseDependencyRule(xElement);

            var visibleTypeNames = ParseVisibleMembersInsideAllowedRule(xElement, allowedDependencyRule);

            if (visibleTypeNames.IsNullOrEmpty())
            {
                visibleTypeNames = null;
            }

            configBuilder.AddAllowRule(allowedDependencyRule, visibleTypeNames);
        }
示例#2
0
 private static void ParseRootNodeAttributes(XElement rootElement, AnalyzerConfigBuilder configBuilder)
 {
     configBuilder.SetIsEnabled(ParseValueType <bool>(rootElement, IsEnabledAttributeName, bool.TryParse));
     configBuilder.SetInheritanceDepth(ParseValueType <int>(rootElement, InheritanceDepthAttributeName, int.TryParse));
     configBuilder.SetIssueKind(ParseValueType <IssueKind>(rootElement, CodeIssueKindAttributeName, Enum.TryParse));
     configBuilder.SetInfoImportance(ParseValueType <Importance>(rootElement, InfoImportanceAttributeName, Enum.TryParse));
     configBuilder.SetAnalyzerServiceCallRetryTimeSpans(ParseReferenceType <TimeSpan[]>(rootElement, AnalyzerServiceCallRetryTimeSpansAttributeName,
                                                                                        TryParseTimeSpans));
     configBuilder.SetChildCanDependOnParentImplicitly(ParseValueType <bool>(rootElement, ImplicitParentDependencyAttributeName, bool.TryParse));
     configBuilder.SetMaxIssueCount(ParseValueType <int>(rootElement, MaxIssueCountAttributeName, int.TryParse));
     configBuilder.SetMaxIssueCountSeverity(ParseValueType <IssueKind>(rootElement, MaxIssueCountSeverityAttributeName, Enum.TryParse));
     configBuilder.SetAutoLowerMaxIssueCount(ParseValueType <bool>(rootElement, AutoLowerMaxIssueCountAttributeName, bool.TryParse));
 }
示例#3
0
        public static ConfigLoadResult CreateWithConfig(AnalyzerConfigBuilder configBuilder)
        {
            if (configBuilder == null)
            {
                throw new ArgumentNullException(nameof(configBuilder));
            }

            var config = configBuilder.ToAnalyzerConfig();

            return(config.IsEnabled
                ? new ConfigLoadResult(AnalyzerConfigState.Enabled, configBuilder, config, null)
                : new ConfigLoadResult(AnalyzerConfigState.Disabled, null, null, null));
        }
示例#4
0
        public static AnalyzerConfigBuilder Parse(XDocument configXml)
        {
            var configBuilder = new AnalyzerConfigBuilder();

            var rootElement = configXml.Element(RootElementName);

            if (rootElement == null)
            {
                throw new Exception($"'{RootElementName}' root element not found.");
            }

            ParseRootNodeAttributes(rootElement, configBuilder);
            ParseChildElements(rootElement, configBuilder);

            return(configBuilder);
        }
示例#5
0
        private static void ParseVisibleMembersElement(XElement xElement, AnalyzerConfigBuilder configBuilder)
        {
            var targetNamespaceName = GetAttributeValue(xElement, OfNamespaceAttributeName);

            if (targetNamespaceName == null)
            {
                throw new Exception($"{GetLineInfo(xElement)}'{OfNamespaceAttributeName}' attribute missing.");
            }

            var targetNamespace = TryAndReportError(xElement, () => new Namespace(targetNamespaceName.Trim()));

            var visibleTypeNames = ParseTypeNameSet(xElement, TypeElementName);

            if (!visibleTypeNames.Any())
            {
                return;
            }

            configBuilder.AddVisibleTypesByNamespace(targetNamespace, visibleTypeNames);
        }
示例#6
0
        private static void ParseChildElements(XElement rootElement, AnalyzerConfigBuilder configBuilder)
        {
            foreach (var xElement in rootElement.Elements())
            {
                switch (xElement.Name.ToString())
                {
                case AllowedElementName:
                    ParseAllowedElement(xElement, configBuilder);
                    break;

                case DisallowedElementName:
                    ParseDisallowedElement(xElement, configBuilder);
                    break;

                case VisibleMembersElementName:
                    ParseVisibleMembersElement(xElement, configBuilder);
                    break;

                default:
                    Trace.WriteLine($"Unexpected element '{xElement.Name}' ignored.");
                    break;
                }
            }
        }
示例#7
0
        private static void ParseDisallowedElement(XElement xElement, AnalyzerConfigBuilder configBuilder)
        {
            var disallowedDependencyRule = ParseDependencyRule(xElement);

            configBuilder.AddDisallowRule(disallowedDependencyRule);
        }