/// <summary>
        /// Gets the rules from XML.
        /// </summary>
        /// <param name="rulesNode">
        /// The rules node.
        /// </param>
        /// <returns>
        /// The StyleCop rules defined in the <see cref="XmlNode"/>.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// Rule Has No Name Attribute.
        /// </exception>
        private static List <StyleCopRule> GetRulesFromXml(XmlNode rulesNode)
        {
            List <StyleCopRule> rules = new List <StyleCopRule>();

            foreach (XmlNode node in rulesNode.ChildNodes)
            {
                switch (node.Name)
                {
                case "RuleGroup":
                {
                    List <StyleCopRule> groupRules = GetRuleGroupRules(node);
                    rules.AddRange(groupRules);
                }

                break;

                case "Rule":
                {
                    StyleCopRule rule = GetRule(node);
                    rules.Add(rule);
                }

                break;
                }
            }

            return(rules);
        }
示例#2
0
        private void Register(StyleCopCore core)
        {
            Dictionary <SourceAnalyzer, List <StyleCopRule> > analyzerRulesDictionary = StyleCopRule.GetRules(core);

            var configurableSeverityItems = new List <Tuple <PsiLanguageType, ConfigurableSeverityItem> >();

            foreach (KeyValuePair <SourceAnalyzer, List <StyleCopRule> > analyzerRule in analyzerRulesDictionary)
            {
                string analyzerName     = analyzerRule.Key.Name;
                string compoundItemName = string.Format(GroupTitleTemplate, analyzerName);

                foreach (StyleCopRule rule in analyzerRule.Value)
                {
                    string ruleName    = rule.RuleID + ": " + SplitCamelCase(rule.Name);
                    string highlightID = GetHighlightID(rule.RuleID);
                    ConfigurableSeverityItem severityItem = new ConfigurableSeverityItem(
                        highlightID,
                        compoundItemName,
                        "StyleCop",
                        ruleName,
                        rule.Description,
                        Severity.WARNING,
                        false,
                        false,
                        null,
                        null);
                    configurableSeverityItems.Add(Tuple.Create((PsiLanguageType)CSharpLanguage.Instance, severityItem));
                }
            }
            this.ConfigurableSeverityItems = configurableSeverityItems;
        }
        private void Register(StyleCopCore core)
        {
            this.registrationLifetimes.Next(
                lifetime =>
            {
                Dictionary <SourceAnalyzer, List <StyleCopRule> > analyzerRulesDictionary = StyleCopRule.GetRules(core);

                // Not the best way of doing this, but better than reflection. Create a "fake" parts catalogue
                // that contains parts representing the attributes that we would specify if we were doing this
                // "properly" and not dynamically based on the rules loaded by StyleCop and any addins (this is
                // compounded by allowing addins to be different per-solution, thanks to the settings subsystem).
                // Adding the catalogue to the global parts catalogue causes ReSharper to automatically evaluate
                // it, and automatically remove it when the lifetime is terminated.
                IPartsCatalogue catalogue = this.CreateFakeCatalogue(analyzerRulesDictionary);
                PartCatalog catalog       = catalogue.WrapLegacy();
                this.partsCatalogueSet.Catalogs.Add(lifetime, catalog, null);
            });
        }