edge-ts
Create strongly typed .NET bindings from Node.js.
In-process interop powered by the awesome edge.js.
Usage
1. Get the package
npm install --save edge-ts
2. Import it
;
Types are bundled with the published package and will be automatically imported.
3. Create your bindings
4. Call them as though they were Typscript functions
meaning .thenconsole.log; // some time passes 42
API
Binding Targets
Bindings can be created to precompiled libraries (*.dll's) or source to be compiled at runtime by edge. Regardless of compile time, the targeted method must be of type Func<object, Task<object>>
.
Source
C# source can be written in-line (as a string) as lambda expressions:
`);
As full classes:
Or referenced as an external file:
Precompiled
Precompiled targets take a similar form:
Or, if you're happy with the defaults, just the path to the assembly:
async<I, O>(«binding target»)
Create an asynchronous function, bound to a CLR/.NET Core/Mono method.
The returned function accepts an input (of type I
) and returns a Promise (of type O
).
Alternatively a Node style callback may be passed as a second argument.
;
sync<I, O>(«binding target»)
Creates a synchronous function, bound to a CLR/.NET Core/Mono method.
The returned function takes a single input argument (or type I
) and returns an output of type O
. If the linked method does not return a synchronous result, an Error will be raised.
; doSomthingmySyncBinding123;
proxy<I, O>(«func»)
Functions may also be passed to the CLR to allow it to call back into Node. These must be of a specific form expected by edge. proxy(..)
may be used to transform a function of type I => O
into this form.
For further information on marshaling data between the environments, refer to the edge.js guide