https://github.com/dogusteknoloji/cs-to-ts
:factory: From C# to TypeScript.
https://github.com/dogusteknoloji/cs-to-ts
csharp generator typescript
Last synced: 10 months ago
JSON representation
:factory: From C# to TypeScript.
- Host: GitHub
- URL: https://github.com/dogusteknoloji/cs-to-ts
- Owner: DogusTeknoloji
- License: mit
- Created: 2018-02-09T07:44:52.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-20T21:44:27.000Z (over 3 years ago)
- Last Synced: 2025-07-31T19:32:37.608Z (11 months ago)
- Topics: csharp, generator, typescript
- Language: C#
- Homepage:
- Size: 116 KB
- Stars: 62
- Watchers: 8
- Forks: 16
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cs-to-ts
[](https://ci.appveyor.com/project/DogusTeknoloji/cs-to-ts)
[](https://coveralls.io/github/DogusTeknoloji/cs-to-ts?branch=master)
[](https://www.nuget.org/packages/CsToTs/)
[](https://github.com/DogusTeknoloji/cs-to-ts/issues)
[](https://raw.githubusercontent.com/DogusTeknoloji/cs-to-ts/master/LICENSE)
[](https://github.com/DogusTeknoloji/cs-to-ts)
[](https://github.com/DogusTeknoloji/cs-to-ts)
From C# to TypeScript.
```CSharp
public class Company: BaseEntity where TAddress: Address, new() {
public string Name { get; set; }
public int EmployeeCount { get; set; }
public decimal Income;
public IList Address { get; set; }
}
var typeScript = CsToTs.Generator.GenerateTypeScript(typeof(Company<>));
```
Generates below TypeScript;
```TypeScript
export interface IBase {
Id: T;
}
export abstract class BaseEntity implements IBase {
UpdateUser: string;
Type: TypeEnum;
Id: TKey;
CreateUser: string;
CreateDate: string;
UpdateDate: string;
IsActive: boolean;
InternalType: any;
}
export class Address extends BaseEntity implements IBase {
PostalCode: number;
CompanyId: number;
City: string;
Detail: string;
}
export class Company extends BaseEntity {
Income: number;
Name: string;
EmployeeCount: number;
Address: Array;
}
export enum TypeEnum {
Type1 = 2,
Type2 = 5,
}
```
You can generate interfaces for classes.
```CSharp
var options = new TypeScriptOptions {
UseInterfaceForClasses = true,
};
var typeScript = Generator.GenerateTypeScript(typeof(Company<>), options);
```
Generates below TypeScript;
```TypeScript
export interface IBase {
Id: T;
}
export interface BaseEntity extends IBase {
UpdateUser: string;
Type: TypeEnum;
Id: TKey;
CreateUser: string;
CreateDate: string;
UpdateDate: string;
IsActive: boolean;
InternalType: any;
}
export interface Address extends BaseEntity {
PostalCode: number;
CompanyId: number;
City: string;
Detail: string;
}
export interface Company extends BaseEntity {
Income: number;
Name: string;
EmployeeCount: number;
Address: Array;
}
export enum TypeEnum {
Type1 = 2,
Type2 = 5,
}
```