Uzamčený XML Documentation with ParamArray

  • 7. března 2012 13:15
     
      Obsahuje kód

    Hello...

    I am trying to use xml documentation tool in my application. one of my methods receives 'ParamArray' as an argument. i want to document this argument elements.

    here is my code

    Public Sub LoadSearch_ByEmployee(ByVal EmployeeID As Integer _
                                            , ByVal FromDate As Date _
                                            , ByVal ToDate As Date _
                                            , ByVal ParamArray Parameters() As String _
                                            ) Implements ITransactionViewCollection.LoadSearch_ByEmployee

    the 'parameters' argument first element would be the company ID, secondly would be department ID. what i want is to add xml documentation for this method and specify the expected values of each index in the ParamArray, something like this

            ''' <param name="Parameters"> 
            ''' <params>
            ''' <param name="Parameters[0]">company ID</param>
            ''' <param name="Parameters[1]">Department ID</param>
             ''' </params>
    

    any idea to do this
    thanks

Všechny reakce

  • 7. března 2012 14:01
     
     Odpovědět

    What if no or more than two arguments are passed? As the number of parameters is undefined by the signature, it's impossible to refer to specific items in the array.

    If you have no, one ore two arguments, I suggest you add overloaded versions of the function or use optional parameters instead of using a ParamArray.


    Armin

  • 15. března 2012 9:38
     
     

    Thanks for your reply Armin, and regarding to method overloading, i cannot overload the method because it is an implementation of base interface method.

    this method should exactly has two paramaters when its implemented in this class, while in another class it may has three or more parameters

  • 15. března 2012 9:58
     
      Obsahuje kód

    Ok, I see. However, documentation is based on the method signature no matter how the method will be called.

    If possible, you can add another method with exactly the parameters you need and write the matching documentation. The function would call the one posted above. You can even declare the above one private so that it's at least not visible to the outside (as long as the referencing expression is of type YourClass and not of type ITransactionViewCollection). It would still implement ITransactionViewCollection.LoadSearch_ByEmployee.

    In other words:

       Interface I
          Sub method(ByVal param1 As Integer, ByVal ParamArray params As String())
       End Interface
       Class Base
          Implements I
    
          Private Sub Method(ByVal param1 As Integer, ByVal ParamArray params() As String) Implements I.method
    
          End Sub
          Public Sub Method(ByVal param1 As Integer, ByVal param2 As String)
             Method(param1, New String() {param2})
          End Sub
       End Class

    You need "New String() {param2}" to call the ParamArray version and to avoid recursion.

    Now you can add a comment to the second method as you like.


    Armin


  • 15. března 2012 10:38
     
     

    thanks for your reply, i will try it and tell you the results...