Method Attributes (Custom Controls)
Adding attributes to your custom control methods provides full integration with Visual Studio features.
In the example of Inheritance / Subclassing, we created a custom control with two additional methods. Those methods worked correctly, but it was obvious that they were add-ons to the standard control – the methods differed from those of the standard control in a number of ways. Those differences can be fixed by attaching the correct attributes to the methods.
The original code for the method was:
Public Sub ItemMoveUp(ByVal selectionindices As ListView.SelectedIndexCollection) For Each Index As Integer In selectionindices If Index <= 0 OrElse Index >= Me.Items.Count Then Exit Sub End If Next For Each Index As Integer In selectionindices Dim Store As ListViewItem = Me.Items(Index) Me.Items.RemoveAt(Index) Me.Items.Insert(Index - 1, Store) Next Me.Refresh() End Sub
That code won’t change. In order to make the method act just like those in the original code we insert attributes prior to the method declaration. But first, be sure to add the following line above the class definition:
Imports System.ComponentModel The attribute code that needs to be added is: <Description("Moves the selected item(s) up one row"), _ EditorBrowsable(True)> _ Public Sub ItemMoveUp(ByVal SelectionIndices As ListView.SelectedIndexCollection)
The attribute “Description” identifies the text that will be displayed in Intellisense to describe the method.
EditorBrowsable(True) ensures that the method is visible in the list of methods for this control.
The order of the attributes does not matter. They are enclosed in angle brackets (<…>) and must be on the same line as the method declaration. The above format, using line continuation, is typical
Method attributes are listed below. This list may not be complete. Note that some attributes are marked as applicable to ‘all’ objects and are therefore included in this list even though they are not relevant to a method.
ActionFilter
ActionName
ASPNetDevelopment
ASPNetDevelopmentServer
AssemblyInitialize
AttachedPropertyBrowsableForType
Authorize
ChangeInterceptor
CodeAccessSecurity
CompilationRelaxations
COMVisible
Conditional
Credential
CustomValidation
DataContractFormat
DataObjectMethod
DataSource
DebuggerHidden
DebuggerNonUserCode
DebuggerStepperBoundary
DebuggerStepThrough
DependsOn
DeploymentItem
Description (See above)
DesignerSerializationVisibility
Display
DisplayName
DLLImport
EditorBrowsable (See above)
ExpectedException
Extension
FaultContract
FileIOPermission
Function
HandleProcessCorruptedStateExceptions
HostType
LoaderOptimisation
ManagementBind
MethodImpl
MTAThread
Obfuscation
Obsolete
OnDeserializing
OnDeserialized
OneWay
OnSerializing
OnSerialized
OperationBehaviour
OperationContract
OutputCache
PermissionSet
PreserveSig
PrincipalPermission
Priority
QueryInterceptor
RegistryPermission
ReliabilityContract
ScriptMethod
ScriptableMember
Security
SecurityCritical
SecurityRole
ServiceKnownType
ServiceControllerPermission
SingleResult
SOAPDocument
SOAPHeader
SpecialName
SQLFunction
SQLProcedure
STAThreadSuppressUnmanagedCodeSecurity
StrongNamedIdentity
TestCleanup
TestInitialize
TestMethod
TestProperty
TimeOut
TransactionFlow
ValidateAntiForgeryToken
WorkItem
WebInvoke
WebGet
WebMethod
XMLInclude
XMLSerializerFormat