The requested page is not available for the requested platform. You are viewing the content for Default platform.

Declare Attribute

Declares an Attribute class descendant for an undeclared attribute under the cursor.

Availability

From the context menus or via shortcuts:

  • when the edit cursor or caret is on an undeclared attribute name.

Example

class TestClass
    {
        [MyAttr("test", 15)]
        private string TestMethod()
    {
        return "Test";
    }
}
Public Class DeclareAttribute
    <MyAttribute("test", 15)>
    Private Function TestMethod() As String
        Return "Test"
    End Function
End Class

Result:

public class MyAttr : Attribute
{
    public MyAttr(string param1, int param2)
    {

    }
}
class TestClass
{
    [MyAttr("test", 15)]
    private string TestMethod()
    {
        return "Test";
    }
}
Public Class MyAttribute
    Inherits Attribute
    Public Sub New(ByVal param1 As String, ByVal param2 As Integer)

    End Sub
End Class
Public Class DeclareAttribute
    <MyAttribute("test", 15)>
    Private Function TestMethod() As String
        Return "Test"
    End Function
End Class