Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Latest commit

 

History

History
50 lines (35 loc) · 1.71 KB

README.md

File metadata and controls

50 lines (35 loc) · 1.71 KB

BlazorInteropGenerator

Nuget Nuget) codecov

What is this?

This project contains code and a Source Generator which can convert a TypeScript Definition to C# Interfaces.

How to use the Source Generator

Create a C# Class Library Project. Add the *.d.ts files that you want converted, also download all the dependencies. File names should be the {PackageName}.d.ts without the Organization/. Update the .csproj with the following settings.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="BlazorInteropGenerator.SourceGenerator" Version="1.0.0-*" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
    <AdditionalFiles Include="*.d.ts" />
  </ItemGroup>

</Project>

Create a .cs file with this format, in this case, the TypeScript Definition must contain an interface called "InterfaceName" The Source Generator will generate the interface and all its dependencies.

using BlazorInteropGenerator;

namespace BlazorInteropGenerator.Sample;

[BlazorInteropGenerator("TSD1.d.ts")]
public partial interface InterfaceName
{

}