示例#1
0
        /// <summary>
        /// Loads settings for rules.
        /// </summary>
        /// <param name="addInNode">
        /// The add-in containing the rules.
        /// </param>
        /// <param name="properties">
        /// The collection of properties to add the rules settings into.
        /// </param>
        /// <param name="propertyDescriptors">
        /// The collection of property descriptors for the add-in.
        /// </param>
        private static void LoadRulesSettings(XmlNode addInNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
        {
            Param.AssertNotNull(addInNode, "addInNode");
            Param.AssertNotNull(properties, "properties");
            Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");

            XmlNode rulesNode = addInNode["Rules"];

            if (rulesNode != null)
            {
                foreach (XmlNode child in rulesNode.ChildNodes)
                {
                    if (string.Equals(child.Name, "Rule", StringComparison.Ordinal))
                    {
                        XmlAttribute name = child.Attributes["Name"];
                        if (name != null && !string.IsNullOrEmpty(name.Value))
                        {
                            string ruleName = name.Value;

                            XmlNode ruleSettings = child["RuleSettings"];
                            if (ruleSettings != null)
                            {
                                LoadPropertyCollection(ruleSettings, properties, propertyDescriptors, ruleName);
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Loads and stores a string property.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property to load.
        /// </param>
        /// <param name="propertyNode">
        /// The node containing the property.
        /// </param>
        /// <param name="properties">
        /// The collection in which to store the property.
        /// </param>
        /// <param name="propertyDescriptors">
        /// The collection of property descriptors.
        /// </param>
        private static void LoadStringProperty(string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
        {
            Param.AssertValidString(propertyName, "propertyName");
            Param.AssertNotNull(propertyNode, "propertyNode");
            Param.AssertNotNull(properties, "properties");
            Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");

            // Get the property descriptor.
            PropertyDescriptor <string> descriptor = propertyDescriptors[propertyName] as PropertyDescriptor <string>;

            // Create and add the property.
            properties.Add(new StringProperty(descriptor, propertyNode.InnerText));
        }
示例#3
0
        /// <summary>
        /// Loads and stores an integer property.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property to load.
        /// </param>
        /// <param name="propertyNode">
        /// The node containing the property.
        /// </param>
        /// <param name="properties">
        /// The collection in which to store the property.
        /// </param>
        /// <param name="propertyDescriptors">
        /// The collection of property descriptors.
        /// </param>
        private static void LoadIntProperty(string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
        {
            Param.AssertValidString(propertyName, "propertyName");
            Param.AssertNotNull(propertyNode, "propertyNode");
            Param.AssertNotNull(properties, "properties");
            Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");

            // Skip corrupted properties.
            int value;

            if (int.TryParse(propertyNode.InnerText, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
            {
                // Get the property descriptor.
                PropertyDescriptor <int> descriptor = propertyDescriptors[propertyName] as PropertyDescriptor <int>;

                // Create and add the property.
                properties.Add(new IntProperty(descriptor, value));
            }
        }
示例#4
0
        /// <summary>
        /// Loads and stores a collection property.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property to load.
        /// </param>
        /// <param name="propertyNode">
        /// The node containing the property.
        /// </param>
        /// <param name="properties">
        /// The collection in which to store the property.
        /// </param>
        /// <param name="propertyDescriptors">
        /// The collection of property descriptors.
        /// </param>
        private static void LoadCollectionProperty(
            string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
        {
            Param.AssertValidString(propertyName, "propertyName");
            Param.AssertNotNull(propertyNode, "propertyNode");
            Param.AssertNotNull(properties, "properties");
            Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");

            // Create and load the inner property collection.
            List <string> innerCollection = new List <string>();

            // Load the value list.
            XmlNodeList valueNodes = propertyNode.SelectNodes("Value");

            if (valueNodes != null && valueNodes.Count > 0)
            {
                foreach (XmlNode valueNode in valueNodes)
                {
                    if (!string.IsNullOrEmpty(valueNode.InnerText))
                    {
                        innerCollection.Add(valueNode.InnerText);
                    }
                }
            }

            // If at least one value was loaded, save the proeprty.
            if (innerCollection.Count > 0)
            {
                // Get the property descriptor.
                CollectionPropertyDescriptor descriptor = propertyDescriptors[propertyName] as CollectionPropertyDescriptor;

                // Create the collection node and pass in the inner collection.
                CollectionProperty collectionProperty = new CollectionProperty(descriptor, innerCollection);

                // Add this property to the parent collection.
                properties.Add(collectionProperty);
            }
        }
示例#5
0
        /// <summary>
        /// Loads and stores a boolean property.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property to load.
        /// </param>
        /// <param name="propertyNode">
        /// The node containing the property.
        /// </param>
        /// <param name="properties">
        /// The collection in which to store the property.
        /// </param>
        /// <param name="propertyDescriptors">
        /// The collection of property descriptors.
        /// </param>
        /// <param name="legacyAnalyzerId">
        /// If the settings node comes from a legacy, pre-4.2 analyzer,
        /// this parameter contains the ID of the legacy analyzer.
        /// </param>
        private static void LoadBooleanProperty(
            string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors, string legacyAnalyzerId)
        {
            Param.AssertValidString(propertyName, "propertyName");
            Param.AssertNotNull(propertyNode, "propertyNode");
            Param.AssertNotNull(properties, "properties");
            Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");
            Param.Ignore(legacyAnalyzerId);

            // Skip corrupted properties.
            bool value;

            if (bool.TryParse(propertyNode.InnerText, out value))
            {
                if (string.IsNullOrEmpty(legacyAnalyzerId))
                {
                    AddBooleanProperty(propertyName, value, properties, propertyDescriptors);
                }
                else
                {
                    if (propertyName == "Enabled")
                    {
                        // Enable or disable all rules mapping to the legacy analyzer.
                        ICollection <string> rules = MapAnalyzerToRules(legacyAnalyzerId);
                        if (rules != null)
                        {
                            foreach (string rule in rules)
                            {
                                AddBooleanProperty(rule + "#Enabled", value, properties, propertyDescriptors);
                            }
                        }
                    }
                    else if (legacyAnalyzerId == "Microsoft.SourceAnalysis.CSharp.Documentation")
                    {
                        if (propertyName == "PublicAndProtectedOnly")
                        {
                            AddBooleanProperty("IgnorePrivates", value, properties, propertyDescriptors);
                            AddBooleanProperty("IgnoreInternals", value, properties, propertyDescriptors);
                        }
                        else if (propertyName == "RequireValueTags")
                        {
                            AddOrUpdateLegacyBooleanProperty("PropertyDocumentationMustHaveValue", value, properties, propertyDescriptors);
                            AddOrUpdateLegacyBooleanProperty("PropertyDocumentationMustHaveValueText", value, properties, propertyDescriptors);
                        }
                        else if (propertyName == "RequireCapitalLetter")
                        {
                            AddOrUpdateLegacyBooleanProperty("DocumentationTextMustBeginWithACapitalLetter", value, properties, propertyDescriptors);
                        }
                        else if (propertyName == "RequirePeriod")
                        {
                            AddOrUpdateLegacyBooleanProperty("DocumentationTextMustEndWithAPeriod", value, properties, propertyDescriptors);
                        }
                        else if (propertyName == "RequireProperFormatting")
                        {
                            AddOrUpdateLegacyBooleanProperty("DocumentationTextMustContainWhitespace", value, properties, propertyDescriptors);
                            AddOrUpdateLegacyBooleanProperty("DocumentationMustMeetCharacterPercentage", value, properties, propertyDescriptors);
                            AddOrUpdateLegacyBooleanProperty("DocumentationTextMustMeetMinimumCharacterLength", value, properties, propertyDescriptors);

                            if (!value)
                            {
                                AddOrUpdateLegacyBooleanProperty("DocumentationTextMustEndWithAPeriod", value, properties, propertyDescriptors);
                                AddOrUpdateLegacyBooleanProperty("DocumentationTextMustBeginWithACapitalLetter", value, properties, propertyDescriptors);
                            }
                        }
                        else
                        {
                            AddBooleanProperty(propertyName, value, properties, propertyDescriptors);
                        }
                    }
                    else if (legacyAnalyzerId == "Microsoft.SourceAnalysis.CSharp.FileHeaders")
                    {
                        if (propertyName == "RequireSummary")
                        {
                            AddOrUpdateLegacyBooleanProperty("FileHeaderMustHaveSummary", value, properties, propertyDescriptors);
                        }
                        else
                        {
                            AddBooleanProperty(propertyName, value, properties, propertyDescriptors);
                        }
                    }
                    else
                    {
                        AddBooleanProperty(propertyName, value, properties, propertyDescriptors);
                    }
                }
            }
        }
示例#6
0
        /// <summary>
        /// Adds or updates a property to enable or disable a rule depending on the value of a
        /// legacy property.
        /// </summary>
        /// <param name="ruleName">
        /// The name of the rule to enable or disable.
        /// </param>
        /// <param name="value">
        /// The value of the legacy property.
        /// </param>
        /// <param name="properties">
        /// The collection of properties.
        /// </param>
        /// <param name="propertyDescriptors">
        /// The collection of property descriptors.
        /// </param>
        private static void AddOrUpdateLegacyBooleanProperty(string ruleName, bool value, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
        {
            Param.AssertValidString(ruleName, "ruleName");
            Param.Ignore(value);
            Param.AssertNotNull(properties, "properties");
            Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");

            // Determine whethere is already an Enabled property for this rule.
            string          propertyName = ruleName + "#Enabled";
            BooleanProperty property     = properties[propertyName] as BooleanProperty;

            if (property == null)
            {
                // Add a new property which enables or disables this rule depending on the
                // value of the legacy property.
                AddBooleanProperty(propertyName, value, properties, propertyDescriptors);
            }
            else if (!value)
            {
                // The rule has already been explictely enabled or disabled. In this case we
                // never enable the rule, but we may disable it if the legacy property is set to false.
                property.Value = false;
            }
        }
示例#7
0
        /// <summary>
        /// Adds a boolean property.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property.
        /// </param>
        /// <param name="value">
        /// The property value.
        /// </param>
        /// <param name="properties">
        /// The collection of properties.
        /// </param>
        /// <param name="propertyDescriptors">
        /// The collection of property descriptors.
        /// </param>
        private static void AddBooleanProperty(string propertyName, bool value, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
        {
            Param.AssertValidString(propertyName, "propertyName");
            Param.Ignore(value);
            Param.AssertNotNull(properties, "properties");
            Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");

            // Get the property descriptor.
            PropertyDescriptor <bool> descriptor = propertyDescriptors[propertyName] as PropertyDescriptor <bool>;

            if (descriptor != null)
            {
                // Create and add the property.
                properties.Add(new BooleanProperty(descriptor, value));
            }
        }