/// <summary>
        /// Gets a setting for the add-in.
        /// </summary>
        /// <param name="addin">The addin being extended.</param>
        /// <param name="document">The document containing the settings.</param>
        /// <param name="propertyName">The name of the setting property.</param>
        /// <returns>Returns the setting or null if it does not exist.</returns>
        public static PropertyValue GetSetting(this StyleCopAddIn addin, CsDocument document, string propertyName)
        {
            Param.RequireNotNull(addin, "addin");
            Param.RequireNotNull(document, "document");
            Param.Ignore(propertyName);

            return(addin.GetSetting(CsDocumentWrapper.Wrapper(document).Settings, propertyName));
        }
        /// <summary>
        /// Adds one violation to the given code element.
        /// </summary>
        /// <param name="addin">The addin being extended.</param>
        /// <param name="element">The element that the violation appears in.</param>
        /// <param name="line">The line in the code where the violation occurs.</param>
        /// <param name="ruleName">The name of the rule that triggered the violation.</param>
        /// <param name="values">String parameters to insert into the violation string.</param>
        public static void AddViolation(this StyleCopAddIn addin, Element element, int line, System.Enum ruleName, params object[] values)
        {
            Param.RequireNotNull(addin, "addin");
            Param.RequireNotNull(element, "element");
            Param.Ignore(line, ruleName, values);

            addin.AddViolation(ElementWrapper.Wrapper(element), line, ruleName, values);
        }
        /// <summary>
        /// Records or fixes an instance of a violation.
        /// </summary>
        /// <param name="addin">The addin being extended.</param>
        /// <param name="ruleName">The name of the rule that triggered the violation.</param>
        /// <param name="violationContext">Context for the violation.</param>
        /// <param name="correctionCallback">Callback which fixes the violation.</param>
        public static void Violation(this StyleCopAddIn addin, System.Enum ruleName, ViolationContext violationContext, CorrectViolationHandler <object> correctionCallback)
        {
            Param.RequireNotNull(addin, "addin");
            Param.Ignore(ruleName);
            Param.RequireNotNull(violationContext, "violationContext");
            Param.RequireNotNull(correctionCallback, "correctViolationCallback");

            addin.Violation(ruleName, violationContext, correctionCallback, null);
        }
        /// <summary>
        /// Records or fixes an instance of a violation.
        /// </summary>
        /// <param name="addin">The addin being extended.</param>
        /// <param name="ruleName">The name of the rule that triggered the violation.</param>
        /// <param name="violationContext">Context for the violation.</param>
        /// <param name="correctionCallback">Callback which fixes the violation.</param>
        /// <param name="correctionContext">Optional callback context.</param>
        /// <typeparam name="T">The type of the callback context.</typeparam>
        public static void Violation <T>(this StyleCopAddIn addin, System.Enum ruleName, ViolationContext violationContext, CorrectViolationHandler <T> correctionCallback, T correctionContext)
        {
            Param.RequireNotNull(addin, "addin");
            Param.Ignore(ruleName);
            Param.RequireNotNull(violationContext, "violationContext");
            Param.RequireNotNull(correctionCallback, "correctViolationCallback");
            Param.Ignore(correctionContext, "correctViolationContext");

            if (addin.Core.RunContext.AutoFix)
            {
                Rule rule = addin.GetRule(ruleName.ToString());

                if (addin.IsRuleEnabled(CsDocumentWrapper.Wrapper(violationContext.Element.Document), rule.Name) &&
                    !addin.IsRuleSuppressed(ElementWrapper.Wrapper(violationContext.Element), rule))
                {
                    correctionCallback(violationContext, correctionContext);
                }
            }
            else
            {
                addin.AddViolation(violationContext.Element, violationContext.LineNumber, ruleName, violationContext.MessageValues);
            }
        }
    /// <summary>
    /// Stores the properties for the given add-in.
    /// </summary>
    /// <param name="addIn">
    /// The add-in.
    /// </param>
    private void StoreAddinProperties(StyleCopAddIn addIn)
    {
      Param.AssertNotNull(addIn, "addIn");

      ICollection<PropertyDescriptor> addInPropertyDescriptors = addIn.PropertyDescriptors;
      if (addInPropertyDescriptors != null && addInPropertyDescriptors.Count > 0)
      {
        List<BooleanProperty> storedProperties = new List<BooleanProperty>(addInPropertyDescriptors.Count);

        foreach (PropertyDescriptor propertyDescriptor in addInPropertyDescriptors)
        {
          if (propertyDescriptor.PropertyType == PropertyType.Boolean && propertyDescriptor.DisplaySettings)
          {
            PropertyDescriptor<bool> booleanPropertyDescriptor = (PropertyDescriptor<bool>)propertyDescriptor;

            // Ensure that the property has a friendly name and a description.
            if (string.IsNullOrEmpty(propertyDescriptor.FriendlyName))
            {
              throw new ArgumentException("The friendly name of the property has not been set.");
            }

            if (string.IsNullOrEmpty(propertyDescriptor.Description))
            {
              throw new ArgumentException("The property description has not been set.");
            }

            BooleanProperty storedProperty = new BooleanProperty(booleanPropertyDescriptor, booleanPropertyDescriptor.DefaultValue);

            this.InitializePropertyState(addIn, storedProperty);

            storedProperties.Add(storedProperty);
          }
        }

        this.properties.Add(addIn, storedProperties.ToArray());
      }
    }
    /// <summary>
    /// Sets the check state for the given property.
    /// </summary>
    /// <param name="addIn">
    /// The addin that owns the property.
    /// </param>
    /// <param name="property">
    /// The property.
    /// </param>
    private void InitializePropertyState(StyleCopAddIn addIn, BooleanProperty property)
    {
      Param.AssertNotNull(addIn, "addIn");
      Param.AssertNotNull(property, "property");

      BooleanProperty mergedProperty = addIn.GetSetting(this.SettingsHandler.MergedSettings, property.PropertyName) as BooleanProperty;
      if (mergedProperty == null)
      {
        property.Value = property.DefaultValue;
      }
      else
      {
        property.Value = mergedProperty.Value;
      }
    }
 /// <summary>
 /// Initializes a new instance of the AddInPropertyCollection class.
 /// </summary>
 /// <param name="addIn">
 /// An analyzer or parser add-in.
 /// </param>
 internal AddInPropertyCollection(StyleCopAddIn addIn)
 {
     Param.AssertNotNull(addIn, "addIn");
     this.addIn = addIn;
 }
 /// <summary>
 /// Initializes a new instance of the AddInPropertyCollection class.
 /// </summary>
 /// <param name="addIn">
 /// An analyzer or parser add-in.
 /// </param>
 internal AddInPropertyCollection(StyleCopAddIn addIn)
 {
     Param.AssertNotNull(addIn, "addIn");
     this.addIn = addIn;
 }