/// <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> /// Gets an element wrapper for the given element. /// </summary> /// <param name="element">The element.</param> /// <returns>Returns the wrapper.</returns> public static ElementWrapper Wrapper(Element element) { Param.AssertNotNull(element, "element"); if (element.Tag != null) { return((ElementWrapper)element.Tag); } Debug.Assert(element.ElementType != ElementType.Document, "Document wrapper should be set in CsDocumentWrapper constructor."); ElementWrapper wrapper = new ElementWrapper(element); element.Tag = wrapper; return(wrapper); }
/// <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> /// Gets an element wrapper for the given element. /// </summary> /// <param name="element">The element.</param> /// <returns>Returns the wrapper.</returns> public static ElementWrapper Wrapper(Element element) { Param.AssertNotNull(element, "element"); if (element.Tag != null) { return (ElementWrapper)element.Tag; } Debug.Assert(element.ElementType != ElementType.Document, "Document wrapper should be set in CsDocumentWrapper constructor."); ElementWrapper wrapper = new ElementWrapper(element); element.Tag = wrapper; return wrapper; }