netCall: Call method

Description Usage Arguments Details Value Examples

View source: R/netCall.R

Description

Call a .Net method member for a given a .Net object.

Usage

1
netCall(x, methodName, ..., wrap = FALSE, out_env = parent.frame())

Arguments

x

a .Net object, which can be an externalptr or a NetObject.

methodName

Method name to call

...

Method arguments

wrap

Specify if you want to wrap externalptr .Net object results into NetObject R6 object. 'FALSEā€œ by default.

out_env

In case of a .Net method with out or ref argument is called, specify on which environment you want to out put this arguments. By default it's the caller environment i.e. parent.frame().

Details

Call a method member for a given .Net object. Ellipses has to keep the .Net arguments method order, the named arguments are not yet supported. If there is conflicts with a method name (many definition in .Net), a score is computed from your argument's order and type. We consider a higher score single value comparing to collection of values.

If you decide to set wrap to TRUE, the function returns a NetObject instead of a raw externalptr. To remind an externalptr is returned only if no one native converter has been found. The NetObject R6 object wrapper can be an inherited R6 class. For more details about inherited NetObject class please see netGenerateR6 function.

The out_env is usefull when the callee .Net method has some out or ref argument. Because in .Net this argument set the given variable in the caller scope. We reflect this mechanism in R. By default the given varable is modify in the parent R environment which means the caller or parent.frame(). You can decide where to redirect the outputed value by specifying another environment. Of course be sure that the variable name exists in this targetd environment.

Value

Returns the .Net result. If a converter has been defined between the .Net type and a R type, the R type will be returned. Otherwise an externalptr or a NetObject if wrap is set to TRUE.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## Not run: 
library(sharper)

package_folder <- path.package("sharper")
netLoadAssembly(file.path(package_folder, "tests", "AssemblyForTests.dll"))

x <- netNew("AssemblyForTests.OneCtorData", 21L)
netCall(x, "ToString")

# wrap result
x <- NetObject$new(ptr = x)
clone <- netCall(x, "Clone", wrap = TRUE)

# out a variable
x <- netNew("AssemblyForTests.DefaultCtorData")
out_variable = 0
netCall(x, "TryGetValue", out_variable)

## End(Not run)

fdieulle/sharper documentation built on Aug. 1, 2020, 4:19 p.m.