Git Product home page Git Product logo

cstots's Introduction

In a C# program, properties are used to define the characteristics of a class. A property typically consists of a pair of get and set accessor methods, which are used to read or set the value of a private field. Properties can be used to control data access and perform logical operations on the properties.

When you decide to share your project with the outside world through an API service, it can be helpful to assist the receiving developer by converting your C# property classes and enums to TypeScript property classes and enums. In this example project, we aim to convert our C# property classes and enum structures to TypeScript property classes and enums, specifically for projects prepared in TypeScript.

The main workflow of the program consists of the following steps:

Firstly, two constants are defined: BasePath and ExportFileName. BasePath represents the path to the folder where the DLL file is located, while ExportFileName represents the name of the generated TypeScript file.

The Main method is executed. This method subscribes to the CurrentDomain_AssemblyResolve event to load the DLL file. By doing so, when a specific DLL file is being loaded, the event is triggered, and the event handler loads the DLL file from the specified path.

The specified DLL file is loaded using the Assembly.Load method. The full path to the file is constructed using Path.Combine and File.ReadAllBytes to read the bytes of the DLL file.

Types are retrieved from the loaded DLL, and valid types are filtered using the IsValidType method. This filtering process checks the following conditions:

If the type is an interface, it is considered invalid and filtered out. If the type is an abstract type, it is considered invalid and filtered out. If the type's access modifier is not public, it is considered invalid and filtered out. If the type is an anonymous type, it is considered invalid and filtered out. If the type is a class, it is considered invalid and filtered out if its name does not end with "DTO" or "DA" or if it does not match a specific naming convention (e.g., "PersonDA"). You can modify this condition according to your own project's naming conventions. The CsToTs.Generator.GenerateTypeScript method is used to generate TypeScript code from the valid types. TypeRenamer and MemberRenamer options are specified for the generated TypeScript code. TypeRenamer and MemberRenamer are custom methods used to convert type and member names to CamelCase.

The generated TypeScript code is printed to the console using the Console.WriteLine method.

A file named ExportFileName is created, and the generated TypeScript code is written to it using the File.WriteAllText method.

I hope this explanation clarifies the process of converting C# property classes to TypeScript property interfaces in the given example program.

cstots's People

Contributors

sabri-dundar avatar

Watchers

 avatar

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.