ParameterInfo

From Xojo Documentation

Class (inherits from Object)

Used to get information about the parameters of a method via the Introspection system.

Properties
IsByref ParameterType

Notes

You obtain an array of ParameterInfo by calling the MethodInfo.GetParameters method. Get the number of parameters for a method by getting the Ubound of the resulting array and cycle through the parameters by examining the ith element. Examine the ParameterType of each element to get its datatype.

Examples

The following reports the data types of the parameters for all methods of a class instance that have parameters.

Var tcp As New TCPSocket
Var myMethods() As Introspection.MethodInfo = _
Introspection.GetType(tcp).GetMethods
For Each method As Introspection.MethodInfo in myMethods
Var myParameters() As Introspection.ParameterInfo = _
method.GetParameters
If Ubound(myParameters) > 0 Then // if a method has any parameters
For j As Integer = 1 To Ubound(myParameters) // loop over the parameters
ListBox1.AddRow(method.Name)
ListBox1.CellValueAt(ListBox1.LastAddedRowIndex, 1)= _
myParameters(j - 1).ParameterType.Name
Next
End If
Next

This example generates signatures for all methods of a class.

Var tcpsocketClass As Introspection.TypeInfo = GetTypeInfo(TCPSocket)
For Each method As Introspection.MethodInfo In tcpsocketClass.GetMethods
// collect parameter types
Var paramTypes() As String
For Each paramInfo As Introspection.ParameterInfo In method.GetParameters
paramTypes.Append(paramInfo.ParameterType.Name)
Next
// build the method signature
If method.ReturnType <> Nil Then
Listbox1.AddRow("Function " + method.Name + "(" + Join(paramTypes, ", ") + ") as " + method.ReturnType.Name)
Else
Listbox1.AddRow("Sub " + method.Name + "(" + Join(paramTypes, ", ") + ")")
End If
Next

See Also

Introspection module; AttributeInfo, ConstructorInfo, MemberInfo, MethodInfo, ObjectIterator, PropertyInfo, TypeInfo classes; GetTypeInfo function.