rafaelsalguero / csharp2ts Goto Github PK
View Code? Open in Web Editor NEWvscode extension to convert C# to typescript
License: MIT License
vscode extension to convert C# to typescript
License: MIT License
A lot of the C# POCOs I am converting end with "Dto" (some use ViewModel, etc). Adding a setting to enter in a string that will be trimmed off the end of any class name would be quite nice. I.e.
{
"csharp2ts.trimEnd": "dto"
}
Which will convert ProjectVersionDto
to ProjectVersion
.
DateTime type converts to "date" intead of "Date"
There doesn't seem to be great support for generics. For example, for the following class, I got the following output:
public class ProjectVersionOverviewDto
{
public ProjectVersionFieldDto<string, object> Payback { get; set; }
public ProjectVersionFieldDto<string, object> NPB { get; set; }
public ProjectVersionFieldDto<string, object> IRR { get; set; }
public ProjectVersionFieldDto<string, object> ProjectSavings { get; set; }
public ProjectVersionFieldDto<string, ProjectVersionListFieldMetadata>[] ProjectLeaders { get; set; }
public ProjectVersionFieldDto<string, object> ProjectScope { get; set; }
public ProjectVersionFieldDto<string, object> ProjectDeliverable { get; set; }
public ProjectVersionFieldDto<string, ProjectVersionListFieldMetadata>[] Positives { get; set; }
public ProjectVersionFieldDto<string, ProjectVersionListFieldMetadata>[] Negatives { get; set; }
public ProjectVersionFieldDto<string, ProjectVersionListFieldMetadata>[] LookingForwards { get; set; }
public ProjectVersionFieldDto<string, ProjectVersionListFieldMetadata>[] Actions { get; set; }
}
export interface ProjectVersionOverviewDto {
export ProjectVersionFieldDto<string, object> Payback { get; set; }
export ProjectVersionFieldDto<string, object> NPB { get; set; }
export ProjectVersionFieldDto<string, object> IRR { get; set; }
export ProjectVersionFieldDto<string, object> ProjectSavings { get; set; }
export ProjectVersionFieldDto<string, ProjectVersionListFieldMetadata>[] ProjectLeaders { get; set; }
export ProjectVersionFieldDto<string, object> ProjectScope { get; set; }
export ProjectVersionFieldDto<string, object> ProjectDeliverable { get; set; }
export ProjectVersionFieldDto<string, ProjectVersionListFieldMetadata>[] Positives { get; set; }
export ProjectVersionFieldDto<string, ProjectVersionListFieldMetadata>[] Negatives { get; set; }
export ProjectVersionFieldDto<string, ProjectVersionListFieldMetadata>[] LookingForwards { get; set; }
export ProjectVersionFieldDto<string, ProjectVersionListFieldMetadata>[] Actions { get; set; }
}
Would be great to get this working :)
Thank you for all your work on this plugin, it's immensely helpful!
Guids are not a datatype in TS, so this should map over to string by default.
Does not work with the "required" (C# 11) keyword. Maybe also not with the "init" keyword.
E.g.
public sealed class AddressDto
{
public required string? Street { get; init; }
public required string? ZipCode { get; init; }
public required string? City { get; init; }
public required string? CountryStateCode { get; init; }
}
becomes
export interface AddressDto {
export required string? Street { get; init; }
export required string? ZipCode { get; init; }
export required string? City { get; init; }
export required string? CountryStateCode { get; init; }
}
First of all โ thank you for this extension!
It will be nice to add an option "Nullable To Optional" to get "?" instead of "| null"
public string? Email { get; set; }
-> email?: string;
Hi,
when converting this C# code:
public MyClass(IServices services,
ILogger<T> logger,
IType<U> value) :
base(services)
{
_logger = logger;
_value = value;
}
I get this Typescript code:
new(services: IServices, value: ILogger<T>): MyClass;
which is missing the logger parameter and got wrong the type of the value parameter.
Hi;
This extension is great ;
Thx dude ๐ฏ
Can you add a feature for map tuple & anonymous types ?
Example
C#
public List<(int Id, object Value)> Properties { get; set; }
Expected TS
Properties: Array<{ Id: number, Value: any }>;
but return TS
Properties: intId[];
It would be great to have a setting to enable converting all field names from PascalCase (i.e. "ThisIsMyField" to "thisIsMyField").
Hi there, just wanted to say "thanks" for the plugin which works nicely and wanted to propse some additional options for configuring the plugin:
it's cool to remove Attributes from properties
Extension should handle initialization at declaration for basic types (standard collections, numbers, strings, etc).
For example, class
public interface Contact {
public int Id { get; set; } = 0;
public string Number { get; set; } = "123-123-123";
public float Score { get; set; } = 1.2f;
public List<Adrress> Addresses { get; set; } = new List<Address>();
}
should be converted to
export interface Contact {
id: number = 0;
number: string = "123-123-123";
score: number = 1.2;
addresses: Adrress[] = [];
}
or skip initialization itself and convert to
export interface Contact {
id: number;
number: string;
score: number;
addresses: Adrress[];
}
Hi,
I have 2 requests:
#region
, #endregion
?For example, this snippet:
namespace Company.Backend.Data.Model
{
public class AuditLog : BaseAuditLog
{
#region Public Properties
public ClientInfo ClientInfo { get; set; }
#endregion
}
}
Would become:
export interface AuditLog extends BaseAuditLog {
clientInfo: ClientInfo;
}
Thanks!
Extension should handle fields conversions.
It would be great if /**
comments could be properly converted. Most stuff has expressions in JS and C#, only C# uses XML while JS uses JSDoc.
namespace Somewhere
{
public enum SomeEnum
{
/**
* <summary>Something GmbH</summary>
* <see href="https://www.example.com"/>
*/
Test
}
}
namespace Somewhere
{
export enum SomeEnum {
/**
* <summary>Something GmbH</summary>
* <see href="https://www.example.com"/>
*/
Test
}
}
namespace Somewhere
{
export enum SomeEnum {
/**
* @summary Something GmbH
* @see https://www.example.com
*/
Test
}
}
Hello, the current version does not support C#9 features bellow:
public class PoirotAutoRunModeDto
{
public int PoirotAutoRunMode { get; init; }
public string Description { get; init; }
}
public record PoirotAutoRunModeDto
{
public int PoirotAutoRunMode { get; init; }
public string Description { get; init; }
}
public record PoirotAutoRunModeDto(
public int PoirotAutoRunMode,
public string Description
);
Since most popular use-case of the extension is to just convert DTOs, I think it can be useful to omit some members on the conversion like private/internal members, methods, simple backing field properties. I don't really think it is good to place all these things into DTO in the first place, but I'm sure that this will have some use-cases.
Hi,
I'd find very useful a command which converts to TypeScript the C# code copied in the clipboard and then pastes it at the cursor's position in the editor.
Having a keyboard schortcut for this command would make it quick to convert & paste C# code from another editor.
Would you accept a PR for this feature?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.