SushiScriptCore 1.5.2
dotnet add package SushiScriptCore --version 1.5.2
NuGet\Install-Package SushiScriptCore -Version 1.5.2
<PackageReference Include="SushiScriptCore" Version="1.5.2" />
<PackageVersion Include="SushiScriptCore" Version="1.5.2" />
<PackageReference Include="SushiScriptCore" />
paket add SushiScriptCore --version 1.5.2
#r "nuget: SushiScriptCore, 1.5.2"
#:package SushiScriptCore@1.5.2
#addin nuget:?package=SushiScriptCore&version=1.5.2
#tool nuget:?package=SushiScriptCore&version=1.5.2
-# SushiScript Library for converting .NET classes to script language classes.
Currently supports
Author
Jeroen Vorsselman @ 2024
Features
- Converts .NET classes to script languages (typescript / ECMAScript)
- Compiled using .NET Standard 2.0
- Supports native types, type inheritance, generics and enum types
- Adds documentation using the generated MS build XML file
- 95% Code coverage
About
string xmlDocPath = Path.Combine(Environment.CurrentDirectory, "Sushi.tests.xml");
// Specify the types to convert using a Type[] or Assembly.ExportedTypes.
Assembly assembly = typeof(PersonViewModel).Assembly;
SushiConverter converter = new SushiConverter(assembly).UseDocumentation(xmlDocPath);
// Specify the script language and convert by invoking ToString().
ConverterOptions options = new ConverterOptions(excludeComments: true);
string result = converter.TypeScript(options).ToString();
Create a new SushiConverter instance with the given Assembly or Type[] that contain the types you want to convert.
These classes must be decorated with the ConvertToScriptAttribute or inherit the IScriptModel interface. Classes can be excluded using the IgnoreForScriptAttribute.
The converter contains a collection of type- and enum-descriptors. These are used to generate script models.
Helpers
You can check if a type exists using:
IsSushiType(IConvertModels converter, Type type, out Type resolvedType) : boolean
You can convert types using:
TypeScriptConverter.ResolveScriptType(Type type, string prefix = "") : string
You can get the script default value using:
TypeScriptConverter.ResolveDefaultValue(IPropertyDescriptor prop) : string
Conversion result
C# class
/// <summary>
/// Simple model to verify complex types.
/// </summary>
public sealed class TypeModel : ViewModel
{
/// <summary>
/// A nullable boolean.
/// </summary>
public bool? NullableBool { get; set; } = null;
/// <summary>
/// A nullable string, defaults to null.
/// </summary>
public string? NullableString { get; set; } = null;
/// <summary>
/// A readonly string.
/// </summary>
public readonly string ReadonlyString = "readonly";
/// <inheritdoc cref="Guid" />
public new Guid Guid { get; set; } = Guid.NewGuid();
/// <summary>
/// A DateTime instance.
/// </summary>
public DateTime Date{get;set;} = DateTime.Now;
public StudentViewModel Student { get; set; } = new StudentViewModel();
public List<StudentViewModel> Students { get; set; }
public Dictionary<string, StudentViewModel[]> StudentPerClass { get; set; } = new ();
}
Typescript class
/**
* Simple model to verify complex types.
* Sushi.Tests.Models.TypeModel
* @extends ViewModel
*/
export class TypeModel extends ViewModel {
/**
* A nullable boolean.
* @type (boolean | null)
*/
nullableBool: boolean | null = null;
/**
* A nullable string, defaults to null.
* @type (string | null)
*/
nullableString: string | null = null;
/**
* .
* @type (string)
*/
override guid: string = "f64db319-ebb2-4b6d-89f4-18abbb2604e7";
/**
* A DateTime instance.
* @type (Date | string | null)
*/
date!: Date | string | null;
student: StudentViewModel = new StudentViewModel();
students: Array<StudentViewModel> = [];
studentPerClass: { [key: string]: Array<StudentViewModel> } = {};
/**
* A readonly string.
* @type (string)
*/
static readonly readonlyString: string = "readonly";
constructor(value: Partial<TypeModel> = {}) {
super(value);
if (value.nullableBool !== undefined) this.nullableBool = value.nullableBool;
if (value.nullableString !== undefined) this.nullableString = value.nullableString;
if (value.guid !== undefined) this.guid = value.guid;
if (value.date !== undefined) this.date = value.date;
if (value.student !== undefined) this.student = value.student;
if (value.students !== undefined) this.students = value.students;
if (value.studentPerClass !== undefined) this.studentPerClass = value.studentPerClass;
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.5.2 | 211 | 12/2/2024 |
| 1.5.1 | 1,107 | 8/30/2024 |
| 1.5.0 | 185 | 6/2/2024 |
| 1.5.0-alpha.2 | 81 | 6/2/2024 |
| 1.5.0-alpha | 107 | 6/2/2024 |
| 1.4.1 | 203 | 5/27/2024 |
| 1.4.0 | 187 | 5/27/2024 |
| 1.3.1 | 248 | 3/25/2024 |
| 1.3.0 | 238 | 3/25/2024 |
| 1.2.5 | 977 | 11/11/2023 |
| 1.2.4 | 463 | 11/11/2023 |
| 1.2.3 | 432 | 11/10/2023 |
| 1.2.2 | 447 | 11/10/2023 |
| 1.2.1 | 435 | 11/8/2023 |
| 1.2.0 | 453 | 11/8/2023 |
| 1.1.6 | 701 | 10/4/2023 |
| 1.1.5 | 732 | 8/16/2023 |
| 1.1.4 | 631 | 8/15/2023 |
| 1.1.3 | 712 | 5/16/2023 |
| 1.1.2 | 689 | 5/15/2023 |
| 1.1.1 | 684 | 5/15/2023 |
| 1.1.0 | 695 | 5/15/2023 |
| 1.0.9 | 782 | 5/10/2023 |
| 1.0.8 | 692 | 5/10/2023 |
| 1.0.7 | 684 | 5/10/2023 |
| 1.0.6 | 724 | 5/10/2023 |
| 1.0.5 | 837 | 1/14/2023 |
| 1.0.4 | 872 | 1/14/2023 |
| 1.0.3 | 852 | 1/12/2023 |
| 1.0.2 | 880 | 1/5/2023 |
| 1.0.1 | 832 | 1/5/2023 |
| 1.0.0 | 867 | 1/3/2023 |
Reworked default value and script type mapping.