SushiScriptCore 1.0.9
See the version list below for details.
dotnet add package SushiScriptCore --version 1.0.9
NuGet\Install-Package SushiScriptCore -Version 1.0.9
<PackageReference Include="SushiScriptCore" Version="1.0.9" />
paket add SushiScriptCore --version 1.0.9
#r "nuget: SushiScriptCore, 1.0.9"
// Install SushiScriptCore as a Cake Addin #addin nuget:?package=SushiScriptCore&version=1.0.9 // Install SushiScriptCore as a Cake Tool #tool nuget:?package=SushiScriptCore&version=1.0.9
Sushi
Library for converting .NET classes to script classes.
Author: Jeroen Vorsselman @ 2023
Main features
- Generates ECMAScript 5, ECMAScript 6 and TypeScript classes using .NET types.
- Support for nested generic types.
- Support for .NET Core.
- Vastly improved compared to its predecessor.
- Creates extended classes and their constructors.
- Simple object mapping.
- Allows custom datatype conversion.
- Improved type dependency tree ordering.
- Adds documentation from the XML file generated on project build.
- 85% Code coverage.
- Assigns explicitly specified default values for "simple" types.
How to use
- Specify what types to use in an
assembly
by adding:- An
ConvertToScriptAttribute
to the class, or; - Inheriting from the
IScriptModel
interface. - You can also exclude models using the
IgnoreForScriptAttribute
.
- An
- Create an instance of the
SushiConverter
:SushiConverter(ICollection<Type> types)
Create an instance using the given collection of types.SushiConverter(ICollection<Type> types, string assemblyDocPath)
Delegates to #1 and adds a path to the XML documentation file.SushiConverter(params Type[] types)
Delegates to #1.SushiConverter(Assembly assembly, string assemblyDocPath)
Delegates to #1 using theassembly.ExportedTypes
and adds a path to the XML documentation file.- REMARK: All given types MUST inherit from the Interface or Attribute or they will be ignored.
- Create a
ModelConverter
for a specific language.
Example
var converter = new SushiConverter(assembly, xmlFilePath);
var script = converter.TypeScript(indent: " ", casing: PropertyNameCasing.Default)
.Convert()
.ConvertEnums()
.ToString();
The following .NET class is used:
/// <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();
public StudentViewModel Student { get; set; } = new StudentViewModel();
public List<StudentViewModel> Students { get; set; }
public List<List<StudentViewModel>> StudentPerClass { get; set; }
}
To generate this TypeScript model:
/**
* Simple model to verify complex types.
* @typedef {Object} TypeModel
* @extends ViewModel
*/
export class TypeModel extends ViewModel {
/** A nullable boolean. */
nullableBool: boolean | null;
/** A nullable string, defaults to null. */
nullableString: string;
student = {} as StudentViewModel;
students = [];
studentPerClass = [];
/** A readonly string. */
readonlyString: string;
constructor(value?: Partial<TypeModel>) {
super(value);
if (value) {
this.nullableBool = value.nullableBool;
this.nullableString = value.nullableString;
this.guid = value.guid;
this.student = value.student;
this.students = value.students;
this.studentPerClass = value.studentPerClass;
this.createdOn = value.createdOn;
this.readonlyString = value.readonlyString;
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
-
net6.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.1 | 516 | 8/30/2024 |
1.5.0 | 87 | 6/2/2024 |
1.5.0-alpha.2 | 61 | 6/2/2024 |
1.5.0-alpha | 65 | 6/2/2024 |
1.4.1 | 109 | 5/27/2024 |
1.4.0 | 112 | 5/27/2024 |
1.3.1 | 160 | 3/25/2024 |
1.3.0 | 146 | 3/25/2024 |
1.2.5 | 930 | 11/11/2023 |
1.2.4 | 426 | 11/11/2023 |
1.2.3 | 375 | 11/10/2023 |
1.2.2 | 376 | 11/10/2023 |
1.2.1 | 361 | 11/8/2023 |
1.2.0 | 395 | 11/8/2023 |
1.1.6 | 635 | 10/4/2023 |
1.1.5 | 660 | 8/16/2023 |
1.1.4 | 560 | 8/15/2023 |
1.1.3 | 629 | 5/16/2023 |
1.1.2 | 594 | 5/15/2023 |
1.1.1 | 564 | 5/15/2023 |
1.1.0 | 595 | 5/15/2023 |
1.0.9 | 624 | 5/10/2023 |
1.0.8 | 588 | 5/10/2023 |
1.0.7 | 592 | 5/10/2023 |
1.0.6 | 604 | 5/10/2023 |
1.0.5 | 736 | 1/14/2023 |
1.0.4 | 753 | 1/14/2023 |
1.0.3 | 730 | 1/12/2023 |
1.0.2 | 768 | 1/5/2023 |
1.0.1 | 747 | 1/5/2023 |
1.0.0 | 757 | 1/3/2023 |
- Simplified library interface > "new SushiConverter().ECMAScript6().Convert().ToString()".
- Support for ECMAScript 5, ECMAScript 6 and TypeScript.
- Classes have a simple object mapper "mapFrom", using Object.assign and _.extend for ES5.
- Improved type dependency tree ordering.
- Support for TypeScript enums.
- Improved conversion for data types.