Exemplo n.º 1
0
        /// <summary>
        /// The execute inner.
        /// </summary>
        /// <param name="solution">
        /// The solution.
        /// </param>
        /// <param name="textControl">
        /// The text control.
        /// </param>
        public override void ExecuteTransactionInner(ISolution solution, ITextControl textControl)
        {
            ICSharpModifiersOwnerDeclaration declaration = Utils.GetTypeClosestToTextControl <ICSharpModifiersOwnerDeclaration>(solution, textControl);

            if (declaration != null)
            {
                string rulesNamespace = this.Rule.Namespace;

                string ruleText = string.Format("{0}:{1}", this.Rule.CheckId, this.Rule.Name);

                IContextBoundSettingsStore settingsStore = PsiSourceFileExtensions.GetSettingsStore(null, solution);

                string justificationText = settingsStore.GetValue((StyleCopOptionsSettingsKey key) => key.SuppressStyleCopAttributeJustificationText);

                IAttributesOwnerDeclaration attributesOwnerDeclaration = declaration as IAttributesOwnerDeclaration;

                CSharpElementFactory factory = CSharpElementFactory.GetInstance(declaration.GetPsiModule());

                ITypeElement typeElement = Utils.GetTypeElement(declaration, "System.Diagnostics.CodeAnalysis.SuppressMessageAttribute");

                IAttribute attribute = factory.CreateAttribute(typeElement);

                ICSharpArgument newArg1 = attribute.AddArgumentAfter(Utils.CreateConstructorArgumentValueExpression(declaration.GetPsiModule(), rulesNamespace), null);

                ICSharpArgument newArg2 = attribute.AddArgumentAfter(Utils.CreateConstructorArgumentValueExpression(declaration.GetPsiModule(), ruleText), newArg1);

                attribute.AddArgumentAfter(Utils.CreateArgumentValueExpression(declaration.GetPsiModule(), "Justification = \"" + justificationText + "\""), newArg2);

                attributesOwnerDeclaration.AddAttributeAfter(attribute, null);
            }
        }
 public static bool IsProtected([NotNull] this ICSharpModifiersOwnerDeclaration declaration)
 {
     return(declaration.HasModifier(CSharpTokenType.PROTECTED_KEYWORD));
 }
 public static bool IsPrivate([NotNull] this ICSharpModifiersOwnerDeclaration declaration)
 {
     return(declaration.HasModifier(CSharpTokenType.PRIVATE_KEYWORD));
 }
 public static bool IsPublic([NotNull] this ICSharpModifiersOwnerDeclaration declaration)
 {
     return(declaration.HasModifier(CSharpTokenType.PUBLIC_KEYWORD));
 }