Code Monkey home page Code Monkey logo

csharp2ts's People

Contributors

aliasadidev avatar amadare42 avatar dependabot[bot] avatar janmarques avatar rafaelsalguero avatar rsalguero-garsalabs avatar supermaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

csharp2ts's Issues

Add option for "TrimEnd" characters

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.

Support for generics

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!

Does not work with the "required" (C# 11) keyword

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; }
}

Option to convert nullable to optional property

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;

Missing parameter in converted constructor

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.

Map Tuple & Anonymous types

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[];

Additional options for configuring the conversion

Hi there, just wanted to say "thanks" for the plugin which works nicely and wanted to propse some additional options for configuring the plugin:

  1. classes are currently always mapped to interfaces. It would be nice to be able to configure to generate a class instead of an interface
  2. modifiers are always removed from public properties. We setup our tslint options to have them as required, so it would be nice to be able to generate them into the result.

Handling of initialization at declaration

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[];
}

Add the option to remove namespace and region

Hi,

I have 2 requests:

  1. Would it be possible to have the option to remove the namespace when converting from a C# class to a TypeScript interface?
  2. Also, could it get rid of the #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!

Convert C# documentation/comments into JsDoc

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.

C#

namespace Somewhere
{
    public enum SomeEnum
    {
        /**
         * <summary>Something GmbH</summary>
         * <see href="https://www.example.com"/>
         */
        Test
    }
}

Currently converted to JS

namespace Somewhere
{
    export enum SomeEnum {
        /**
         * <summary>Something GmbH</summary>
         * <see href="https://www.example.com"/>
         */
        Test
    }
}

Should be converted to JS

namespace Somewhere
{
    export enum SomeEnum {
        /**
         * @summary Something GmbH
         * @see https://www.example.com
         */
        Test
    }
}

Support for C#9

Hello, the current version does not support C#9 features bellow:

  • C# 9 init modifier. Conversion of this class fails.
        public class PoirotAutoRunModeDto
	{
		public int PoirotAutoRunMode { get; init; }
		public string Description { get; init; }
	}
  • C# 9 records. Conversion of this class fails.
        public record PoirotAutoRunModeDto
	{
		public int PoirotAutoRunMode { get; init; }
		public string Description { get; init; }
	}
  • C# 9 records. Conversion of this class fails.
        public record PoirotAutoRunModeDto(
              public int PoirotAutoRunMode,
              public string Description
        );

Add option to omit members

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.

Convert C# to TS when pasting code

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.