netCallStatic: Call static method

Description Usage Arguments Details Value Examples

View source: R/netCallStatic.R

Description

Call a static .Net method for a given .Net type name

Usage

1
2
3
4
5
6
7
netCallStatic(
  typeName,
  methodName,
  ...,
  wrap = FALSE,
  out_env = parent.frame()
)

Arguments

typeName

Full .Net type name

methodName

Method name to call

...

Method arguments

wrap

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

out_env

In case of .Net method with out or ref argument, 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 static method for a given .Net type name. Ellipses has to keep the .net arguments method order, the named arguments are not supported yet. 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
20
21
22
23
24
25
## Not run: 
library(sharper)

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

type <- "AssemblyForTests.StaticClass"
netCallStatic(type, "CallWithInteger", 2L)
netCallStatic(type, "CallWithIntegerVector", c(2L, 3L))

# Method selection single value vs vector values
netCallStatic(type, "SameMethodName", 1.23)
netCallStatic(type, "SameMethodName", c(1.24, 1.25))
netCallStatic(type, "SameMethodName", c(1.24, 1.25), 12L)

# wrap result
x <- NetObject$new(ptr = netNew("AssemblyForTests.DefaultCtorData"))
clone <- netCallStatic(type, "Clone", x, wrap = TRUE)

# out a variable
out_variable = 0
netCallStatic(type, "TryGetValue", out_variable)

## End(Not run)

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