CLR Extender Reference

CLRInvokeStaticMethod Function

Description »

Invokes a Static (C#) or Shared (VB) method, a Static Method is a Class Method which IS NOT associated with any particular object instance.

CLRInvokeStaticMethod(cType, cMethod [, eParam1 , eParam2, ...])

Parameters

cType
Specifies the name of the Type on which to invoke the method. Include the type's FullName (i.e. System::IO::Directory).
Note:

The cType has to be accessible from one of the assemblies loaded with SetCLRClassLibrary.

cMethod
Specifies the method to invoke on cType (example: GetDirectories).
Note:

cMethod has to be a Static or Shared method, for the call to succeed.

[, eParam1 , eParam2, ...]
Specifies the parameters to pass to the method. See the class documentation to check the number and type of parameters required or use Assembly Browser to see the parameters needed.

If the class has several static methods with the same name (this is the method is OVERLOADED), the call is routed to the first method overload compatible with the passed parameters.

Return Value

Variant. The returned type depends of the return type of the called method. See the Class documentation for information about the returned type. You can also use the Assembly Browser to see the Return Type. If the returned type is a .NET Array the returned value is NOT A FOXPRO ARRAY, instead a .NET ARRAY is returned

Example »

The following example Invokes the static method "GetDirectories" of the class "System::IO::Directory" and then lists the contents of the returned array. After that, calls GetLogicalDrives and then lists the drives available in the computer.

LOCAL aDirectories, i, aDrives
aDirectories = CLRInvokeStaticMethod("system::io::directory","Getdirectories",HOME())
FOR i = 1 TO aDirectories.Length
	? aDirectories.GetValue(m.i)
ENDFOR
aDrives = CLRInvokeStaticMethod("system::IO::directory","GetLogicalDrives")
FOR i = 1 TO aDrives.Length
	? aDrives.GetValue(m.i)
ENDFOR
Remarks »
CLRInvokeStaticMethod provides you with a quick way to call ANY static (shared) in the .NET Framework. A lot of functionality in the .NET Framework is only available through Static Methods. Static Methods are not accessible through COM Interop so TLBEXP-orting the types DOES NOT give you access to those methods.

If you are going to call the same static method several times (for example, in a for loop), it is faster to get a reference to the type through CLRGetTypeReference and then to call the method directly in the returned type.

aDirectories = CLRInvokeStaticMethod("system::io::directory","Getdirectories",HOME())
Other Resources »

CLRGetTypeReference Function


Send comments about this topic to eTecnologia.net.