I wouldn't try map it. I'd call function1 passing in the result from Response() as a parameter. Probably lots of ways to do this
public async void GetSomeValue()
{
string response = Response();
//pass the result to electron/node
if(function1 != null)
{
await function1(response);
}
}
All 5 comments
I have no relation to this repo. but I can tell you how I do it using electron-edge with an Electron app I have. C# code is loaded as a DLL, running on windows only.
Bind the functions in the DLL in electron
let assemblyFile = __dirname + "/my.dll" //path to DLL, I'm simply storing the DLL in the current electron directory
const init = edge.func({
assemblyFile : assemblyFile,
typeName: 'MyNameSpace.MyClassName',
methodName: 'InitCallbacks' // I have a method in my MyClassName called this
});
I create a javascript object with the functions I want to be called one way from the C# code
app.on('ready', () => {
...
const registerCallbacks = {
function1 : (data) => {
//doSomething with data
console.log(data);
},
function2: (data) => {
//doSometing with data
console.log(data);
}
//and so on
};
//call the c# init function passing in the object with the javascript functions
init(registerCallBacks);
...
};
In c# MyClass
public class MyClass {
...
private Func<object, Task<object>> function1;
private Func<object, Task<object>> function2;
...
public async Task<object> InitCallbacks(dynamic input)
{
return await Task.Run<object>(() =>
{
IDictionary<string, object> callbackFunctions = (IDictionary<string, object>)input;
//assign the electron function to the class variable,
function1 = (Func<object, Task<object>>)callbackFunctions["function1"];
function2 = (Func<object, Task<object>>)callbackFunctions["function2"];
return new { };
});
}
}
I can then use function1, function2 in the c# code to call back to electron any time
I have no relation to this repo. but I can tell you how I do it using electron-edge with an Electron app I have. C# code is loaded as a DLL, running on windows only.
Bind the functions in the DLL in electron
let assemblyFile = __dirname + "/my.dll" //path to DLL, I'm simply storing the DLL in the current electron directory
const init = edge.func({
assemblyFile : assemblyFile,
typeName: 'MyNameSpace.MyClassName',
methodName: 'InitCallbacks' // I have a method in my MyClassName called this
});
I create a javascript object with the functions I want to be called one way from the C# code
app.on('ready', () => {
...
const registerCallbacks = {
function1 : (data) => {
//doSomething with data
console.log(data);
},
function2: (data) => {
//doSometing with data
console.log(data);
}
//and so on
};
//call the c# init function passing in the object with the javascript functions
init(registerCallBacks);
...
};
In c# MyClass
public class MyClass {
...
private Func
public async Task InitCallbacks(dynamic input)
{
return await Task.Run(() =>
{
IDictionary callbackFunctions = (IDictionary)input;
//assign the electron function to the class variable,
function1 = (Func>)callbackFunctions["function1"];
function2 = (Func>)callbackFunctions["function2"];
return new { };
});
}
}
I can then use function1, function2 in the c# code to call back to electron any time
Most helpful comment
I wouldn't try map it. I'd call function1 passing in the result from Response() as a parameter. Probably lots of ways to do this