microsoft / microsoft/node-api-dotnet
How do I export a C# function with a `JSValue` argument?
@jasongin is already working on this.
Since Jan 10, 2025.
- Dominant language
- C#
- Stars
- 783
- Forks
- 80
- PR merge metrics
- No merged PRs in 30d
Description
As per issue title, I'm trying to export a C# class method using TypeExporter.ExportType, but the method is not exported due to the following check, which explicitly disallows JSValue argument types and causes the method to be skipped:
The method has the following signature:
public async Task<JSValue> sendMessage(JSValue parameters)
The purpose of the C# function is:
- to call
JSON.stringify - parse the result with
System.Text.Json - execute some C# code,
- serialize the result with
System.Text.Json - call
JSON.parseagain to return the result to nodeJS.
(I know, the JSON round-trip could be removed in the future by creating a DTO type, but the JSON data currently has a dynamic structure and needs some work)
Changing the signature to a string and using JSON.stringify in NodeJs is a workaround to make the method appear, but I'd like to pass a JSON object directly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.