Share via


CLRInterop::staticInvoke Method

Calls a static method on a CLR data type.

Syntax

client server public static CLRObject staticInvoke(
    str className, 
    str methodName, 
     params)

Run On

Called

Parameters

  • className
    Type: str
    The name of the class that owns the method to call.
  • methodName
    Type: str
    The name of the static CLR method to call.
  • params
    Type: [T:]
    The arguments, if there are any, to the method that is specified in the _methodName parameter.

Return Value

Type: CLRObject Class
The CLRObject that contains the value that is returned by the static CLR method; otherwise, nullNothingnullptrunita null reference (Nothing in Visual Basic).

Remarks

If an attacker can control input to the staticInvoke method, a security risk exists. Therefore, this method runs under Code Access Security. Calls to this method on the server require permission. Make sure that the user has development privileges by setting the security key to SysDevelopment on the control that calls this method.

If an error occurs when you call the get_Now method, the Exception::ClrError exception is thrown.

Examples

The following example calls the get_Now method on the System.DateTime CLR class and prints the results in the Infolog.

static void Job7(Args _args) 
{ 
    CLRObject clrObj; 
    InteropPermission perm; 
    System.DateTime dateTime; 
 
    perm = new InteropPermission(InteropKind::ClrInterop); 
    if (perm == null) 
    { 
        return; 
    } 
    perm.assert(); 
 
    dateTime = CLRInterop::staticInvoke( 
                   "System.DateTime", 
                   "get_Now" ); 
    info(dateTime.ToString()); 
    CodeAccessPermission::revertAssert(); 
     
    pause; 
     
    // This is the same code using CLR syntax. 
    // dateTime = System.DateTime::get_Now(); 
    // info(dateTime.ToString()); 
}

See Also

Reference

CLRInterop Class