/// <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> /// Gets the analyzer tag for the given element. /// </summary> /// <param name="element">The element.</param> /// <returns>Returns the analyzer tag.</returns> public static object GetAnalyzerTag(this Element element) { Param.RequireNotNull(element, "element"); ElementWrapper wrapper = ElementWrapper.Wrapper(element); if (wrapper == null) { throw new InvalidOperationException(); } return(wrapper.AnalyzerTag); }
/// <summary> /// Gets the analyzer tag for the given element. /// </summary> /// <param name="element">The element.</param> /// <param name="value">The value to set.</param> public static void SetAnalyzerTag(this Element element, object value) { Param.RequireNotNull(element, "element"); Param.Ignore(value); ElementWrapper wrapper = ElementWrapper.Wrapper(element); if (wrapper == null) { throw new InvalidOperationException(); } wrapper.AnalyzerTag = value; }
/// <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); } }