Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <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);
            }
        }