Description Active bindings Methods Examples
NetObject R6 class to wrap an 'externalptr“which represents a .Net object.
Ptrexternalptr of the wrapped .Net object
new()Create a new NetObject.
NetObject$new(typeName = NULL, ptr = NULL, ...)
typeName.Net full type name.
ptrexternalptr of the .Net object.
...Property setters
You can use 2 ways to instanciate a .NetObject.
If you specify the externalptr through the ptr parameter,
this pointer will be wrapped and stored into the Ptr active binding.
Otherwise if your .Net class has a default constructor you can specify the typeName
as netNew(typeName) does.
The ellipsis parameter can be use to setup the .Net properties. This feature
works with both building ways.
You can use it as follow o <- NetObject$new(typeName, Name = "My name", Id = 1L)
A new wrapped .Net object.
get()Gets a property value
NetObject$get(propertyName, wrap = TRUE)
propertyNameProperty name
wrapSpecify if you want to wrap a externalptr .Net object into a NetObject object. 'TRUE“ by default.
Allows you to get a property value for a .Net object.
The result will be converted if the type mapping is defined. All native C# types are mapped to R types
but you can define custom converters in C# for that see the C# RDotNetConverter class.
By default wrap is set to TRUE. If there is no native convertion found between .Net type and R type,
the result is wrapped into NetObject instance.
A best R6 type can be chosen if this type exists. This R6 class has to inherit from NetObject
and has to have the same name than the C# class. You can generate automatically this inherited class.
For more details about this feature please see the netGenerateR6 function.
If you prefer get a raw externalptr to the .Net object,
This function is aquivalent to call netGet(o$Ptr, propertyName)
Returns the .Net property value.
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.
set()Sets a property value
NetObject$set(propertyName, value)
propertyNameProperty name.
valuevalue to set
Allows you to set a property value of a .Net object. The input value will be converted from R type to a .Net type.
If the property value isn't a native C# type or a mapped conversion type,
you have to use an externalptr on .Net object or a NetObject R6 instance.
You can define custom converters in C# for that see RDotNetConverter C# class.
This function is aquivalent to call netSet(o$Ptr, propertyName, value).
call()Call a .Net method member.
NetObject$call(methodName, ..., wrap = TRUE, out_env = parent.frame())
methodNameMethod name
...Method arguments
wrapSpecify if you want to wrap externalptr .Net object into NetObject R6 object. 'TRUE“ by default.
out_envIn 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().
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.
This function is aquivalent to call netCall(o$Ptr, methodName).
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.
as()Cast the current R6 class to another.
NetObject$as(className)
classNameR6 class name to cast.
If the R6 className already exists the wrapped externalptr
which represents a .Net object will be transfer to a new R6
instance of type className.
a new R6 instance of type className.
getType()Gets NetType description of wrapped .Net object
NetObject$getType()
print()Print the object
NetObject$print(...)
....
clone()The objects of this class are cloneable with this method.
NetObject$clone(deep = FALSE)
deepWhether to make a deep clone.
1 2 3 4 5 6 7 8 9 10 11 | ## Not run:
library(sharper)
package_folder <- path.package("sharper")
netLoadAssembly(file.path(package_folder, "tests", "AssemblyForTests.dll"))
x <- netNew("AssemblyForTests.DefaultCtorData")
object <- NetObject$new(ptr = x)
object$set("Name", "My Name")
object$get("Name")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.