0

Is it possible to add a custom attribute to parameters of method.

For instance I have method as follows

''' <summary>
'''  Get addition of given two number
''' </summary>
''' <param name="firstNumber">First number which participate in addition</param>
''' <param name="secondNumber">Second number which participate in addition</param>
''' <returns></returns>
''' <remarks></remarks>
Public Function Add(firstNumber As Integer, secondNumber As Integer) As Double
    Return firstNumber + secondNumber
End Function

along with the "param name" and it description, Am i able to add any Tagged value to the parameter?

vaduganathan
  • 141
  • 1
  • 1
  • 11
  • I don't understand your requirement. By "attribute", do you mean an XML attribute in the documentation or a [.NET attribute](http://stackoverflow.com/q/20346/87698)? Maybe you could give a short example of what your code would like if the feature you want were available. – Heinzi Mar 24 '15 at 08:49
  • Yes you can, it's simple XML. But you will have to adapt your reader in case you are reading the title from outside. – Nadeem_MK Mar 24 '15 at 08:50
  • #Nadeem_MK can you provide sample / url which have sample? – vaduganathan Mar 24 '15 at 09:23
  • You can add anything you want. But the likelihood that you'll ever see it back in, say, IntelliSense or auto-generated documentation are zero. It is only willing to use the documented XML attributes. – Hans Passant Mar 24 '15 at 11:46

1 Answers1

0

Frist we have to define calss, whose Attribute-Targe as Parameter as follows

<AttributeUsage(System.AttributeTargets.Parameter)>
Public Class SomeParameterAttribute
    Inherits Attribute

    Private m_Something As String

    Public Sub New(something As String)
        m_Something = something
    End Sub

    Public Property Something As String
        Get
            Return m_Something
        End Get
        Set(value As String)
            m_Something = value
        End Set
    End Property

End Class

And then we can add the this attribute the any prameter as follows

''' <summary>
'''  Get addition of given two values
''' </summary>
''' <param name="firstNumber">First number which participate in addition</param>
''' <param name="secondNumber">Second number which participate in addition</param>
''' <returns></returns>
''' <remarks></remarks>
Public Function Add(<SomeParameterAttribute("Something about first number")> firstNumber As Integer, _
                    <SomeParameterAttribute("Something about second number")> secondNumber As Integer) As Double
    Return firstNumber + secondNumber
End Function

Thank you so much for all other reply and whoever put effort for this.

vaduganathan
  • 141
  • 1
  • 1
  • 11