Class

MethodInfo


Description

Provides information on the methods of the class instance via the Introspection system.

Properties

Name

Type

Read-Only

Shared

IsPrivate

Boolean

IsProtected

Boolean

IsPublic

Boolean

IsShared

Boolean

Name

String

ReturnType

TypeInfo

Methods

Name

Parameters

Returns

Shared

GetAttributes

AttributeInfo()

GetParameters

ParameterInfo()

Invoke

base As Object, Optional params() As Variant

base As Object, Optional params() As Variant

Variant

Property descriptions


MethodInfo.IsPrivate

IsPrivate As Boolean

If True, the item has Private scope.

This property is read-only.

The following example checks the IsPrivate property before taking an action.

Var d As DateTime = DateTime.Now
For Each prop As Introspection.PropertyInfo In Introspection.GetType(d).GetProperties
  If prop.IsPrivate Then
    ' take an action here..
  End If
Next

MethodInfo.IsProtected

IsProtected As Boolean

Is True, the item has Protected scope.

This property is read-only.

Var d As DateTime = DateTime.Now
For Each prop As Introspection.PropertyInfo In Introspection.GetType(d).GetProperties
  If prop.IsProtected Then
    ' take an action here..
  End If
Next

MethodInfo.IsPublic

IsPublic As Boolean

If True, the item has Public scope.

This property is read-only.

This example checks the IsPublic property before taking an action.

Var d As DateTime = DateTime.Now
For Each prop As Introspection.PropertyInfo In Introspection.GetType(d).GetProperties
  If prop.IsPublic Then
    ' take an action here..
  End If
Next

MethodInfo.IsShared

IsShared As Boolean

If True, it is a shared method and does not require a Self parameter when called by Introspection.

This property is read-only.


MethodInfo.Name

Name As String

The name of the item. This is only the class name. To get the full namespace path, use FullName instead.

This property is read-only.

This code gets the list of properties for the passed type instance.

Var d As DateTime = DateTime.Now
For Each prop As Introspection.PropertyInfo In Introspection.GetType(d).GetProperties
  ListBox1.AddRow(prop.Name)
Next

MethodInfo.ReturnType

ReturnType As TypeInfo

If the method returns a value, this is the datatype of the returned value. If the method does not return a value, ReturnType is Nil.

This property is read-only.

Method descriptions


MethodInfo.GetAttributes

GetAttributes As AttributeInfo()

Returns an array of AttributeInfo objects.

The following gets the attributes of window1.

Var myAttributes() As Introspection.AttributeInfo = Introspection.GetType(Window1).GetAttributes

MethodInfo.GetParameters

GetParameters As ParameterInfo()

Returns an array of ParameterInfo items. Use GetParameters to obtain datatype information on the method's parameters.


MethodInfo.Invoke

Invoke(base As Object, Optional params() As Variant)

Invokes the method, given its info object and an instance of the class that created it. You can use Nil as the base object if calling a shared method. Pass an array of variants for the method's parameter values. You will get an OutOfBoundsException if the number of parameters does not match or an IllegalCastException if the types do not match.


MethodInfo.Invoke

Invoke(base As Object, Optional params() As Variant) As Variant

Invokes the method, given its info object and an instance of the class that created it. You can use Nil as the base object if calling a shared method. Pass an array of variants for the method's parameter values. You will get an OutOfBoundsException if the number of parameters does not match or an IllegalCastException if the types do not match.

Sample code

The following gets the methods of the DateTime class instance:

Var d As DateTime = DateTime.Now
Var myDbMethods() As Introspection.MethodInfo = _
  Introspection.GetType(d).GetMethods
For Each method As Introspection.MethodInfo In MyDbMethods
  Listbox1.AddRow(method.Name)
Next

Compatibility

All project types on all supported operating systems.