Skip to content

Generates Blazor -> Javascript strongly typed interop methods.

License

Notifications You must be signed in to change notification settings

surgicalcoder/BlazorInteropGenerator

Repository files navigation

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, then add an AdditionalFile in your .csproj named "ApiClientGenerator.json", like so:

<ItemGroup>
     <AdditionalFiles Include="BlazorInterop.json" />
</ItemGroup>

Once that's done, add the settings file and change as required:

{
  "JavascriptFile": "wwwroot\\assets\\js\\blazorinterop.js",
  "JSInit": [
    "window={}"
  ],
  "MainJsObject": "window.blazor",
  "InvokeVoidString": "await JSRuntime.InvokeVoidAsync(\"{0}\", {1});",
  "InvokeString": "return await JSRuntime.InvokeAsync<T>(\"{0}\",{1});"
}

The JSInt option is there if you need to init a value, such as if you have all of your methods under window.blazor, you need to init window.

About

Generates Blazor -> Javascript strongly typed interop methods.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages