-
Notifications
You must be signed in to change notification settings - Fork 0
Support Invoking Modules/Classes from JS in C# #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Does this mean that you want to call a member function of an object on the JS side as an instance of a class object from the .NET side? .NET Proxy feature on #5 (comment) for example? This issue eventually pivoted to being able to pass a callback function. The reason is that I felt that if the callback function could be implemented, it would no longer be necessary. However, the callback function is a different method than the realization of a proxy feature, so it is not exactly a replacement.... Do you think this function should be there? |
I think not to this extent but I want to be able to call functions from a class/module from JavaScript in C# Let's say this is JS let calculator = new Calculator(); // declaring using let will not attach calculator to window
messenger.RegisterObject(calculator) // so we need a way to expose it to C# I should be able to do this in C# invokeClientMethod(`calculator.add`, 1,2); |
@geocine Sorry too later :( I remembered that I had implemented it to accept that operation, so I wrote some test code: JavaScript classes like this one: class JSCalculator {
async add(a, b) { return a + b; }
async sub(a, b) { return a - b; }
};
var jscalc = new JSCalculator(); It can be called like this: var result_jscalc_add = await messenger.InvokePeerMethodAsync<int>(
"jscalc.add", 1, 2); If you could check out this commit and give it a try, you can confirm this. However, it may just be my environment, but now in Edge WebView2, the |
I can see this is possible from C# to JS like so
How do I do this for JS? It seems I can only invoke functions from the window context.
The text was updated successfully, but these errors were encountered: