https://github.com/surgicalcoder/BlazorInteropGenerator
Generates Blazor -> Javascript strongly typed interop methods.
https://github.com/surgicalcoder/BlazorInteropGenerator
Last synced: about 1 month ago
JSON representation
Generates Blazor -> Javascript strongly typed interop methods.
- Host: GitHub
- URL: https://github.com/surgicalcoder/BlazorInteropGenerator
- Owner: surgicalcoder
- License: mit
- Created: 2022-02-12T11:06:40.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-11-20T16:38:50.000Z (6 months ago)
- Last Synced: 2025-03-30T01:46:38.636Z (2 months ago)
- Language: C#
- Size: 41 KB
- Stars: 20
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- csharp-source-generators - BlazorInteropGenerator -   Generates Blazor -> Javascript strongly typed interop methods, by parsing the Javascript it self and generating extension methods for IJSRuntime. (Source Generators / Webprogramming)
- awesome-blazor - BlazorInteropGenerator -   Github [Octicons](https://primer.style/design/foundations/icons/) Generates Blazor -> Javascript strongly typed interop methods, by parsing the Javascript it self and generating extension methods for IJSRuntime. (Source generators / Others)
- RSCG_Examples - https://github.com/surgicalcoder/BlazorInteropGenerator
README
# BlazorInteropGenerator
Generates Blazor -> Javascript strongly typed interop methods, by parsing the Javascript it self and generating extension methods for IJSRuntime.## Usage
Firstly, add the project from Nuget - [GoLive.Generator.BlazorInterop](https://www.nuget.org/packages/GoLive.Generator.BlazorInterop/), then add an AdditionalFile in your .csproj named "BlazorInterop.json", like so:
```
```
Once that's done, add the settings file and change as required:
```
{
"Files": [
{
"Output": "JSInterop.cs",
"Source": "wwwroot\\blazorinterop.js",
"Namespace": "GoLive.Generator.BlazorInterop.Playground.Client",
"ObjectToInterop": "window.blazorInterop",
"Init": ["window={}"]
}
],
"InvokeVoidString": "await JSRuntime.InvokeVoidAsync(\"{0}\", {1});",
"InvokeString": "return await JSRuntime.InvokeAsync(\"{0}\",{1});"
}```
### Description of Each Option
- Files: An array of file objects specifying details of the files involved in the interop process.
- Output: The name of the output C# file to be generated.
- Source: The path to the source JavaScript file used for the interop.
- Namespace: The namespace used in the generated C# file.
- ObjectToInterop: The JavaScript object used for the interop.
- Init: An array of initialization scripts executed before the interop. In this example above, we are interop'ing to window.blazorInterop, and window doesn't exist, so we have to create it.
- InvokeVoidString: A template string for invoking a JavaScript function that does not return a value using JSRuntime.InvokeVoidAsync. Placeholders {0} and {1} are replaced with the function name and arguments, respectively.
- InvokeString: A template string for invoking a JavaScript function that returns a value using JSRuntime.InvokeAsync. Placeholders {0} and {1} are replaced with the function name and arguments, respectively.