How to use
- Select the desired C# code
- Open the command pallete and run
Convert C# to TypeScript
Simple C# POCOs to TypeScript converter.
Supports:
- Automatic properties
- Remove attributes
- Detect common types such as int, long, ...
On your workspace or user settings.json
:
// Place your settings in this file to overwrite default and user settings.
{
/** True for camelCase, false for preserving original name. Default is false */
"csharp2ts.propertiesToCamelCase": false,
/** Removes specified postfixes from property names, types & class names. Can be array OR string. Case-sensitive. */
"csharp2ts.trimPostfixes": "",
/** Whether or not trim postfixes recursive. (e.g. with postfixes 'A' & 'B' PersonAAB will become PersonAA when it's false & Person when it's true) */
"csharp2ts.recursiveTrimPostfixes": false,
/** Ignore property initializer */
"csharp2ts.ignoreInitializer": true
/** True to remove method bodies, false to preserve the body as-is */
"csharp2ts.removeMethodBodies": true,
/** True to remove class constructors, false to treat then like any other method */
"csharp2ts.removeConstructors": false,
/** 'signature' to emit a method signature, 'lambda' to emit a lambda function. 'controller' to emit a lambda to call an async controller */
"csharp2ts.methodStyle": 'signature',
/** True to convert C# byte array type to Typescript string, defaults to true since the serialization of C# byte[] results in a string */
"csharp2ts.byteArrayToString": true,
/** True to convert C# DateTime and DateTimeOffset to Typescript (Date | string), defaults to true since the serialization of C# DateTime results in a string */
"csharp2ts.dateToDateOrString": true,
/** Modifiers to remove. Ex. if you want to remove private and internal members set to ['private', 'internal'] */
"csharp2ts.removeModifiers": [],
/** If setted, any property or field that its name matches the given regex will be removed, Ex. if you want to remove backing fields starting with underscore set to "_[a-z][a-zA-Z0-9]*" */
"csharp2ts.removeNameRegex": "",
/** True to convert classes to interfaces, false to convert classes to classes. Default is true */
"csharp2ts.classToInterface": true,
/** True to preserve fields and property modifiers. Default is false */
"csharp2ts.preserveModifiers": false
/** True to convert a C# dictionary into a typescript Record instead of { [key: t]: V }. Default is false */
"dictionaryToRecord": false;
}
- Initial release of the tool
- Support multiline automatic properties
- Added support for
bool
- Fixed formatting differences between C# and TS
- Fixed bug where DateTime was translated to 'date' instead of 'Date'
- Added detection for scope modifiers on C# properties
- Fixed readme animation
- Bug fix: Automatic properties without any visibility modifiers where skipping line jumps
- Support for the 'new' modifier on automatic properties
- Support for C# fat arrow automatic properties
- Full C# type parser
- Support for C# generics
- Support for nullable types: Convert
int?
orNullable<int>
toint | null
- Convert C#
Dictionary<string, T>
to{ [key: string]: T }
- Convert C#
Tuple<TA, TB, TC>
to{ Item1: TA, Item2: TB, Item3: TC }
- Convert C#
List<T>
toT[]
- Bug fix: Getter only properties where not correctly parsed
- Support for cammelCase/PascalCase. Configurable with the
"csharp2ts.propertiesToCamelCase"
setting
- Documentation for settings added
- new
trimPostfixes
andrecursiveTrimPostfixes
config. Thanks amadare42
csharp2ts.propertiesToCamelCase
is set tofalse
by default
- Bug fix: Property initializer correctly parsed
- New
csharp2ts.ignoreInitializer
config double
correctly parsed
- Support method and constructor signature conversion and body removing
- Emit method signature or method empty implementation, see the
csharp2ts.methodStyle
configuration - Added a C# XML Docs parser, improving generated JSDoc
- Improved code base
- Support for the
Task
type
- Bug fix: Support for international characters on identifiers
- Bug fix: Support for international characters on type names
- Improved attribute parsing and removing
- New method body style
controller
- Improved class constructor parsing
- New configuration for type generators:
byteArrayToString
anddateToDateOrString
- Bug fix: Support for fields
- Bug fix: Translation was wrong on some special cases with generic types mixed with arrays
- New config:
classToInterface
. Convertclass
tointerface
orclass
- New config:
preserveModifiers
. Preserve properties and field modifiers. - New config:
removeWithModifier
. Remove fields and properties with the given modifiers. - New config:
removeNameRegex
. Remove fields and properties that its name match the given regex.
- Improved parsing for
partial
classes and multiple inheritances
- Bug fix: Incorrectly parsed generic type on certain conditions. Thanks @labarilem
- Support for C# 9
- New config: removeSpecialKeywords Remove virtual and #nullable statements. Thanks @supermaz
- New config: removeUsings Remove using/import statements. Thanks @supermaz
- New config: dictionaryToRecord Convert
Dictionary
toRecord
. Thanks @CorwinDickey