Introducing xcore
What is xcore
xcore is a Node.js® plugin enabling the use of .NET netstandard libraries with javascript. netstandard is a new specification by Microsoft representing a set of .NET API which can be used across many .NET implementations such as .NET Framework and .NET Core. - https://github.com/dotnet/standard
Basically xcore allows any Node.js script to use .NET code. xcore is entirely authored by Raffaele Rialdi - @raffaeler
Please refer to the repo github issues to report bugs, ask questions or suggestions.
Show me the code ...
Install
npm install xcorenode
xcorenode is one of the flavors of xcore. In the future I will publish the Electron variant.
Load and initialize xcore
var xcore = require(__dirname + '\\node_modules\\xcorenode\\xcorenode.node');
var netPath = __dirname + "\\node_modules\\xcorenode\\binw10x64";
// load the dll (initializer is optional), then load the class OrderManager (full qualified name)
xcore.initialize(netPath, "SampleLibrary.dll", "SampleLibrary.Initializer");
Load the .net metadata. This operation is done for just the entry-point class of a graph.
xcore.loadClass("SampleLibrary.OrderSample. OrderManager, SampleLibrary");
Create an instance of the .NET class
var om = new xcore.OrderManager("raf");
Call methods
console.log(om.Add("Hello, ", "world"));
Walk the graph. Metadata for the Order class is loaded automatically
console.log(om.SelectedOrder.Name);
Asynchronous calls
om.AddAsync(2, 3, function(res){
console.log(res);
});
Subscribing events
var cookie = om.addEventHandler("OrderReady", function(sender, args){
console.log("sender: " + sender.SelectedOrderName, " args:" + args.Name);
});
Unsubcscribe events
om.removeEventHandler("OrderReady", cookie);
Much more is supported!
Please refer to the github repo for more info.