Skip to content

Instantly share code, notes, and snippets.

@andriybuday
Last active August 29, 2015 14:13
Show Gist options
  • Save andriybuday/6db8d6213e03b40ed6b7 to your computer and use it in GitHub Desktop.
Save andriybuday/6db8d6213e03b40ed6b7 to your computer and use it in GitHub Desktop.
Integrating Edge.js into C# project
(function () {
if ('undefined' === typeof Calc2D) {
Calc2D = {};
if ('undefined' !== typeof window) {
window.Calc2D = Calc2D;
} else {
GLOBAL.Calc2D = Calc2D;
}
}
Calc2D.add2DPoints = function (a, b) {
return {
x: a.x + b.x,
y: a.y + b.y
};
};
})();
var Calc2D = require('../../calc2D.js');
module.exports = function (data, callback) {
var obj = global[data.className];
var result = obj[data.functionName](data.a, data.b);
callback(null, result);
};
using System;
using EdgeJs;
namespace LearnEdgeJs
{
class Program
{
public void Start()
{
var func = Edge.Func(@"return require('../edgeEntryPoint.js')");
var invoke = func.Invoke(new
{
className = "Calc2D",
functionName = "add2DPoints",
a = new { x = 1, y = 2 },
b = new { x = 10, y = 20 }
});
var c = (dynamic)invoke.Result;
Console.WriteLine("C: y={0}, y={1}", c.x, c.y);
}
static void Main(string[] args)
{
new Program().Start();
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment