Exemple #1
0
        public static string ValidOnToString(AttributeTargets attributeTargets)
        {
            var str = attributeTargets.ToString();

            switch (str)
            {
            case "Class": return("Type");

            default: return(str);
            }
        }
        public async Task TestSimpleAttributeClass(AttributeTargets attributeTarget, int codeActionIndex)
        {
            var attributeTargetsValue = "AttributeTargets." + attributeTarget.ToString();

            await new VerifyCS.Test
            {
                TestCode                 = @"
using System;

class C : Attribute
{
}
",
                ExpectedDiagnostics      = { GetCA1018CSharpResultAt(4, 7, "C"), },
                CodeActionIndex          = codeActionIndex,
                CodeActionEquivalenceKey = attributeTargetsValue,
                FixedCode                = @"
using System;

[AttributeUsage(" + attributeTargetsValue + @")]
class C : Attribute
{
}
",
            }.RunAsync();

            await new VerifyVB.Test
            {
                TestCode            = @"
Imports System

Class C
    Inherits Attribute
End Class
",
                ExpectedDiagnostics = { GetCA1018BasicResultAt(4, 7, "C"), },
                FixedCode           = @"
Imports System

<AttributeUsage(AttributeTargets.All)>
Class C
    Inherits Attribute
End Class
",
            }.RunAsync();
        }
 // Generated using https://roslynquoter.azurewebsites.net/
 public static AttributeListSyntax GenerateSyntax(AttributeTargets usageTarget)
 {
     return(SyntaxFactory.AttributeList(
                SyntaxFactory.SingletonSeparatedList <AttributeSyntax>(
                    SyntaxFactory.Attribute(
                        SyntaxFactory.QualifiedName(
                            SyntaxFactory.IdentifierName("System"),
                            SyntaxFactory.IdentifierName("AttributeUsage")))
                    .WithArgumentList(
                        SyntaxFactory.AttributeArgumentList(
                            SyntaxFactory.SingletonSeparatedList <AttributeArgumentSyntax>(
                                SyntaxFactory.AttributeArgument(
                                    SyntaxFactory.MemberAccessExpression(
                                        SyntaxKind.SimpleMemberAccessExpression,
                                        SyntaxFactory.MemberAccessExpression(
                                            SyntaxKind.SimpleMemberAccessExpression,
                                            SyntaxFactory.IdentifierName("System"),
                                            SyntaxFactory.IdentifierName("AttributeTargets")),
                                        SyntaxFactory.IdentifierName(usageTarget.ToString())))))))));
 }