

Blazor 和 TypeScript 互操作工具库
source link: https://www.cnblogs.com/shanyou/p/15844604.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Blazor 和 TypeScript 互操作工具库
现在传统的前端框架React,Angular 和 Vue等都使用TypeScript 构建库,Blazor 虽然使用C# 作为主要的语言,它的生态非常需要借力他的弟弟TypeScript 来丰富生态,从语法上来说TypeScript 已经和C# 非常接近, Blazor 也存在和JavaScript 互操作的API,今天就给大家介绍这么一个工具库EventHorizon.Blazor.TypeScript.Interop.Generator,它是一个开源项目,Github Repository: canhorn/EventHorizon.Blazor.TypeScript.Interop.Generator(https://github.com/canhorn/EventHorizon.Blazor.TypeScript.Interop.Generator/tree/main/Tool/EventHorizon.Blazor.TypeScript.Interop.Tool)。同时发布了NuGet Package: EventHorizon.Blazor.TypeScript.Interop.Generator
还有一个.NET工具包 EventHorizon.Blazor.TypeScript.Interop.Tool 可用于从 CLI 轻松生成项目,从 TypeScript 定义文件的抽象语法树生成 C# Blazor Interop 抽象,为用户提供一个生成的项目,该项目可以更轻松地从 C# 与 JavaScript 库进行交互,生成的项目可以与 Blazor WASM 一起使用,以便与 C# 中的 JavaScript 进行交互,这为大多数 JavaScript 库提供了一个来自 C# 的易于使用的接口。它使用 JSRuntime 直接与 C# 中的基础 JavaScript 进行互操作,这是通过自定义互操作抽象完成的。
作者为了验证这样的一个互操作工具库的可用性,通过一个 Three.js类似的一款WebGL开发框架 Babylon , 示例站点:BabylonJS 生成的示例站点(https://wonderful-pond-05f7b3b10.azurestaticapps.net/)
工具包最新是基于.NET 6,所以要先安装.NET 6 SDK, 然后通过下面的命令安装工具包
dotnet tool install -g EventHorizon.Blazor.TypeScript.Interop.Tool
具体用法参考仓库的Readme:https://github.com/canhorn/EventHorizon.Blazor.TypeScript.Interop.Generator/tree/main/Tool/EventHorizon.Blazor.TypeScript.Interop.Tool
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK