public static bool IsSettingOverwritten(PropertyValue localProperty, PropertyValue parentProperty)
 {
     if ((parentProperty == null) || (localProperty == null))
     {
         return false;
     }
     if (localProperty.PropertyType != parentProperty.PropertyType)
     {
         throw new ArgumentException(Strings.ComparingDifferentPropertyTypes);
     }
     return localProperty.OverridesProperty(parentProperty);
 }
 public bool IsAddInSettingOverwritten(StyleCopAddIn addIn, string propertyName, PropertyValue localProperty)
 {
     Param.RequireNotNull(addIn, "addIn");
     Param.RequireValidString(propertyName, "propertyName");
     if (this.parentSettings == null)
     {
         return false;
     }
     PropertyValue parentProperty = null;
     PropertyCollection addInSettings = this.parentSettings.GetAddInSettings(addIn);
     if (addInSettings != null)
     {
         parentProperty = addInSettings[propertyName];
     }
     if (parentProperty != null)
     {
         return IsSettingOverwritten(localProperty, parentProperty);
     }
     if (localProperty.HasDefaultValue)
     {
         return !localProperty.IsDefault;
     }
     return true;
 }
示例#3
0
 /// <summary>
 /// Determines whether this property overrides the given property.
 /// </summary>
 /// <param name="parentProperty">The parent property to compare with.</param>
 /// <returns>Returns true if this property overrides the given property.</returns>
 public abstract bool OverridesProperty(PropertyValue parentProperty);
示例#4
0
 internal void SetAddInSettingInternal(StyleCopAddIn addIn, PropertyValue property)
 {
     AddInPropertyCollection addInSettings = this.GetAddInSettings(addIn);
     if (addInSettings == null)
     {
         addInSettings = new AddInPropertyCollection(addIn);
         this.SetAddInSettings(addInSettings);
     }
     addInSettings.Add(property);
 }
        public void SetAddInSetting(StyleCopAddIn addIn, PropertyValue property)
        {
            Param.RequireNotNull(addIn, "addIn");
            Param.RequireNotNull(property, "property");

            this.SetAddInSettingInternal(addIn, property);
        }
 public bool IsGlobalSettingOverwritten(string propertyName, PropertyValue localProperty)
 {
     Param.RequireValidString(propertyName, "propertyName");
     if (this.parentSettings == null)
     {
         return false;
     }
     PropertyValue parentProperty = this.parentSettings.GlobalSettings[propertyName];
     if (parentProperty == null)
     {
         return false;
     }
     return IsSettingOverwritten(localProperty, parentProperty);
 }
        /// <summary>
        /// Saves a single property value.
        /// </summary>
        /// <param name="rootCollectionNode">The collection node containing the property.</param>
        /// <param name="property">The property to save.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <returns>Returns true if the property was saved; otherwise false.</returns>
        private static bool SavePropertyValue(XmlNode rootCollectionNode, PropertyValue property, string propertyName)
        {
            Param.AssertNotNull(rootCollectionNode, "rootCollectionNode");
            Param.AssertNotNull(property, "property");
            Param.AssertValidString(propertyName, "propertyName");

            bool propertyWritten = false;

            switch (property.PropertyType)
            {
                case PropertyType.Boolean:
                    propertyWritten |= SaveBooleanProperty(rootCollectionNode, property as BooleanProperty, propertyName);
                    break;

                case PropertyType.Int:
                    propertyWritten |= SaveIntProperty(rootCollectionNode, property as IntProperty, propertyName);
                    break;

                case PropertyType.String:
                    propertyWritten |= SaveStringProperty(rootCollectionNode, property as StringProperty, propertyName);
                    break;

                case PropertyType.Collection:
                    propertyWritten |= SaveCollectionProperty(rootCollectionNode, property as CollectionProperty, propertyName);
                    break;

                default:
                    Debug.Fail("Unexpected property type.");
                    break;
            }

            return propertyWritten;
        }
 private static bool SaveRuleProperty(XmlNode rootNode, PropertyValue property, string ruleName, string propertyName)
 {
     XmlNode newChild = rootNode.SelectSingleNode("Rules");
     if (newChild == null)
     {
         newChild = rootNode.OwnerDocument.CreateElement("Rules");
         rootNode.AppendChild(newChild);
     }
     XmlNode node2 = newChild.SelectSingleNode("Rule[@Name=\"" + ruleName + "\"]");
     if (node2 == null)
     {
         node2 = rootNode.OwnerDocument.CreateElement("Rule");
         newChild.AppendChild(node2);
         XmlAttribute node = rootNode.OwnerDocument.CreateAttribute("Name");
         node.Value = ruleName;
         node2.Attributes.Append(node);
     }
     XmlNode node3 = node2.SelectSingleNode("RuleSettings");
     if (node3 == null)
     {
         node3 = rootNode.OwnerDocument.CreateElement("RuleSettings");
         node2.AppendChild(node3);
     }
     return SavePropertyValue(node3, property, propertyName);
 }
        /// <summary>
        /// Determines whether the local property overrides the parent property.
        /// </summary>
        /// <param name="localProperty">The local property.</param>
        /// <param name="parentProperty">The parent property.</param>
        /// <returns>Returns true if the local property overrides the parent property.</returns>
        public static bool IsSettingOverwritten(PropertyValue localProperty, PropertyValue parentProperty)
        {
            Param.Ignore(localProperty, parentProperty);

            // If either the parent property or the local property is not set, then the setting is not overwritten.
            if (parentProperty == null || localProperty == null)
            {
                return false;
            }

            // Ensure that the two properties are the same kind of property.
            if (localProperty.PropertyType != parentProperty.PropertyType)
            {
                throw new ArgumentException(Strings.ComparingDifferentPropertyTypes);
            }

            return localProperty.OverridesProperty(parentProperty);
        }
示例#10
0
        /// <summary>
        /// Sets a setting for the given add-in.
        /// </summary>
        /// <param name="addIn">The add-in.</param>
        /// <param name="property">The setting property to set.</param>
        internal void SetAddInSettingInternal(StyleCopAddIn addIn, PropertyValue property)
        {
            Param.AssertNotNull(addIn, "addIn");
            Param.AssertNotNull(property, "property");

            AddInPropertyCollection properties = this.GetAddInSettings(addIn);
            if (properties == null)
            {
                properties = new AddInPropertyCollection(addIn);
                this.SetAddInSettings(properties);
            }

            properties.Add(property);
        }
示例#11
0
        /// <summary>
        /// Determines whether the given global setting overrides the parent setting.
        /// </summary>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="localProperty">The local value of the property.</param>
        /// <returns>Returns true if the given global setting overrides the parent setting.</returns>
        public bool IsGlobalSettingOverwritten(string propertyName, PropertyValue localProperty)
        {
            Param.RequireValidString(propertyName, "propertyName");
            Param.Ignore(localProperty);

            if (this.parentSettings == null)
            {
                return false;
            }

            // Try to find this property in the parent settings file.
            PropertyValue parentProperty = this.parentSettings.GlobalSettings[propertyName];
            if (parentProperty == null)
            {
                return false;
            }

            return IsSettingOverwritten(localProperty, parentProperty);
        }
示例#12
0
        public bool IsAddInSettingOverwritten(StyleCopAddIn addIn, string propertyName, PropertyValue localProperty)
        {
            Param.RequireNotNull(addIn, "addIn");
            Param.RequireValidString(propertyName, "propertyName");
            Param.Ignore(localProperty);

            if (this.parentSettings == null)
            {
                return false;
            }

            // Try to find this property in the parent settings file.
            PropertyValue parentProperty = null;

            PropertyCollection parentParserProperties = this.parentSettings.GetAddInSettings(addIn);
            if (parentParserProperties != null)
            {
                parentProperty = parentParserProperties[propertyName];
            }

            if (parentProperty == null)
            {
                // If there is no parent setting, then the parent is set to the default. If the local setting
                // is not set to the default, then we consider that the local setting is overriding the parent setting.
                return !localProperty.HasDefaultValue || !localProperty.IsDefault;
            }

            // Compare the local and parent properties.
            return IsSettingOverwritten(localProperty, parentProperty);
        }
示例#13
0
        /// <summary>
        /// Merges two collection properties together.
        /// </summary>
        /// <param name="mergedPropertyCollection">The merged property collection.</param>
        /// <param name="originalProperty">The original property to merge.</param>
        /// <param name="overridingProperty">The overriding property to merge.</param>
        private static void MergeCollectionProperties(
            PropertyCollection mergedPropertyCollection, PropertyValue originalProperty, PropertyValue overridingProperty)
        {
            Param.AssertNotNull(mergedPropertyCollection, "mergedPropertyCollection");
            Param.AssertNotNull(originalProperty, "originalProperty");
            Param.AssertNotNull(overridingProperty, "overridingProperty");

            CollectionProperty originalCollectionProperty = (CollectionProperty)originalProperty;
            CollectionProperty overridingCollectionProperty = (CollectionProperty)overridingProperty;

            // Create a new merged collection property.
            CollectionProperty mergedCollectionProperty = new CollectionProperty(
                (CollectionPropertyDescriptor)originalCollectionProperty.PropertyDescriptor);
            mergedPropertyCollection.Add(mergedCollectionProperty);

            // Add each of the strings from the overriding collection.
            foreach (string value in overridingCollectionProperty.Values)
            {
                mergedCollectionProperty.Add(value);
            }

            // If necessary, also add the strings from the original collection.
            if (originalCollectionProperty.Aggregate)
            {
                foreach (string value in originalCollectionProperty.Values)
                {
                    if (!mergedCollectionProperty.Contains(value))
                    {
                        mergedCollectionProperty.Add(value);
                    }
                }
            }
        }
示例#14
0
 private static void MergeCollectionProperties(PropertyCollection mergedPropertyCollection, PropertyValue originalProperty, PropertyValue overridingProperty)
 {
     CollectionProperty property = (CollectionProperty) originalProperty;
     CollectionProperty property2 = (CollectionProperty) overridingProperty;
     CollectionProperty property3 = new CollectionProperty((CollectionPropertyDescriptor) property.PropertyDescriptor);
     mergedPropertyCollection.Add(property3);
     foreach (string str in property2.Values)
     {
         property3.Add(str);
     }
     if (property.Aggregate)
     {
         foreach (string str2 in property.Values)
         {
             if (!property3.Contains(str2))
             {
                 property3.Add(str2);
             }
         }
     }
 }
示例#15
0
        /// <summary>
        /// Saves a rule property.
        /// </summary>
        /// <param name="rootNode">The node to store the property collection beneath.</param>
        /// <param name="property">The property to save.</param>
        /// <param name="ruleName">The name of the rule.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <returns>Returns true if the property was saved; otherwise false.</returns>
        private static bool SaveRuleProperty(XmlNode rootNode, PropertyValue property, string ruleName, string propertyName)
        {
            Param.AssertNotNull(rootNode, "rootNode");
            Param.AssertNotNull(property, "property");
            Param.AssertValidString(ruleName, "ruleName");
            Param.AssertValidString(propertyName, "propertyName");

            // Get or create the Rules node under the root.
            XmlNode rulesNode = rootNode.SelectSingleNode("Rules");
            if (rulesNode == null)
            {
                rulesNode = rootNode.OwnerDocument.CreateElement("Rules");
                rootNode.AppendChild(rulesNode);
            }

            // Get or create the Rule node.
            XmlNode ruleNode = rulesNode.SelectSingleNode("Rule[@Name=\"" + ruleName + "\"]");
            if (ruleNode == null)
            {
                ruleNode = rootNode.OwnerDocument.CreateElement("Rule");
                rulesNode.AppendChild(ruleNode);

                XmlAttribute attrib = rootNode.OwnerDocument.CreateAttribute("Name");
                attrib.Value = ruleName;
                ruleNode.Attributes.Append(attrib);
            }

            // Get or create the RuleSettings node.
            XmlNode ruleSettings = ruleNode.SelectSingleNode("RuleSettings");
            if (ruleSettings == null)
            {
                ruleSettings = rootNode.OwnerDocument.CreateElement("RuleSettings");
                ruleNode.AppendChild(ruleSettings);
            }

            // Save the setting.
            return SavePropertyValue(ruleSettings, property, propertyName);
        }
示例#16
0
        /// <summary>
        /// Sets the given property on the add-in.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="property">The property to set.</param>
        public void SetSetting(WritableSettings settings, PropertyValue property)
        {
            Param.RequireNotNull(settings, "settings");
            Param.RequireNotNull(property, "property");

            settings.SetAddInSetting(this, property);
        }
示例#17
0
        private static bool SavePropertyValue(XmlNode rootCollectionNode, PropertyValue property, string propertyName)
        {
            bool flag = false;
            switch (property.PropertyType)
            {
                case PropertyType.String:
                    return (flag | SaveStringProperty(rootCollectionNode, property as StringProperty, propertyName));

                case PropertyType.Boolean:
                    return (flag | SaveBooleanProperty(rootCollectionNode, property as BooleanProperty, propertyName));

                case PropertyType.Int:
                    return (flag | SaveIntProperty(rootCollectionNode, property as IntProperty, propertyName));

                case PropertyType.Collection:
                    return (flag | SaveCollectionProperty(rootCollectionNode, property as CollectionProperty, propertyName));
            }
            return flag;
        }