SushiScriptCore 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SushiScriptCore --version 1.0.0
                    
NuGet\Install-Package SushiScriptCore -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SushiScriptCore" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SushiScriptCore" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SushiScriptCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SushiScriptCore --version 1.0.0
                    
#r "nuget: SushiScriptCore, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=SushiScriptCore&version=1.0.0
                    
Install SushiScriptCore as a Cake Addin
#tool nuget:?package=SushiScriptCore&version=1.0.0
                    
Install SushiScriptCore as a Cake Tool

Sushi

Library for converting .NET classes to script classes.

Author: Jeroen Vorsselman @ 2023

GitHub


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:
    • ES5 classes use (optional) _.extend from UnderscoreJS.
    • ES6 and TypeScript use Object.assign().
  • Allows custom datatype conversion.
  • Improved type dependency tree ordering.
  • Adds documentation from the XML file generated on project build.
  • 84% Code coverage. <br>

How to use

  1. Specify what types to use in an assembly by adding:
    1. An ConvertToScriptAttribute to the class, or;
    2. Inheriting from the IScriptModel interface.
    3. You can also exclude models using the IgnoreForScriptAttribute.
  2. Create an instance of the SushiConverter:
    1. SushiConverter(ICollection<Type> types) Create an instance using the given collection of types.
    2. SushiConverter(ICollection<Type> types, string assemblyDocPath) Delegates to #1 and adds a path to the XML documentation file.
    3. SushiConverter(params Type[] types) Delegates to #1.
    4. SushiConverter(Assembly assembly, string assemblyDocPath) Delegates to #1 using the assembly.ExportedTypes and adds a path to the XML documentation file.
    5. REMARK: All given types MUST inherit from the Interface or Attribute or they will be ignored.
  3. Create a ModelConverter for a specific language.

Example

var converter = new SushiConverter(assembly, xmlFilePath);
var script = converter.TypeScript()
    .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 boolean.
	/// </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 boolean. */
	NullableString: string;
	Student: StudentViewModel | null;
	Students: Array<StudentViewModel | null>;
	StudentPerClass: Array<Array<StudentViewModel | null>>;
	/** A readonly string. */
	ReadonlyString: string;

	constructor();
	constructor(value?: any) {
		super();

		if (!(value instanceof Object))
			return;

		this.NullableBool = value.NullableBool;
		this.NullableString = value.NullableString;
		this.Student = value.Student;
		this.Students = value.Students;
		this.StudentPerClass = value.StudentPerClass;
		this.ReadonlyString = value.ReadonlyString;
	}

	static mapFrom(obj: any): TypeModel {
		return Object.assign(new TypeModel(), obj);
	}
}
Product 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.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.2 110 12/2/2024
1.5.1 841 8/30/2024
1.5.0 104 6/2/2024
1.5.0-alpha.2 65 6/2/2024
1.5.0-alpha 74 6/2/2024
1.4.1 121 5/27/2024
1.4.0 128 5/27/2024
1.3.1 171 3/25/2024
1.3.0 156 3/25/2024
1.2.5 939 11/11/2023
1.2.4 434 11/11/2023
1.2.3 388 11/10/2023
1.2.2 386 11/10/2023
1.2.1 368 11/8/2023
1.2.0 401 11/8/2023
1.1.6 643 10/4/2023
1.1.5 670 8/16/2023
1.1.4 569 8/15/2023
1.1.3 645 5/16/2023
1.1.2 610 5/15/2023
1.1.1 587 5/15/2023
1.1.0 615 5/15/2023
1.0.9 651 5/10/2023
1.0.8 605 5/10/2023
1.0.7 609 5/10/2023
1.0.6 623 5/10/2023
1.0.5 754 1/14/2023
1.0.4 770 1/14/2023
1.0.3 750 1/12/2023
1.0.2 786 1/5/2023
1.0.1 767 1/5/2023
1.0.0 775 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.