C
C#CrosRoad95

❔ Source generator, generating type script definitions at compile time

I would like to make a automatic type script definition from code, i consider to use source generator to do that, is it a good idea? is source generator able to do this?
C
CrosRoad95511d ago
a bit more context: i'm using https://github.com/microsoft/ClearScript to run js from c#, i made a list of methods, classes that are availiable to use in js and now i would like to loop through all of them and generate types
A
Anton511d ago
You probably want swagger and NSwag if you're doing a rest api
C
CrosRoad95511d ago
not rest api just plain text file with typescript definition
T
Thinker511d ago
An SG can output non-cs source files afaik.
A
Anton511d ago
And if you're doing grpc, you just need to use their compiler
C
CrosRoad95511d ago
^ thats what i want i already use grpc lib for it
A
Anton511d ago
well it supports generating clients for different languages
C
CrosRoad95511d ago
https://andrewlock.net/creating-a-source-generator-part-1-creating-an-incremental-source-generator/ i wonder if it will okey class Foo{ void Bar(){} } do some reflection magic, generate:
interface Foo {
bar(): void
}
interface Foo {
bar(): void
}
T
Thinker511d ago
Are you talking about SGs or reflection
A
Anton511d ago
what's your use case
C
CrosRoad95511d ago
generate typescript types from c# classes is it able to read comments?
T
Thinker511d ago
yes
C
CrosRoad95511d ago
ok, i will try it then
A
Anton511d ago
what for
C
CrosRoad95511d ago
did they fix so i no longer need to restart vs to see new generated code?
T
Thinker511d ago
nope Also, you might want to consider using an attribute to denote the types which should be targeted
C
CrosRoad95511d ago
i'm using ClearScript tags to do it attributes* not tags how can i tell an IIncrementalGenerator to generate content, for example html files? Generator attribute doesn't like "Html" as first parameter
T
Thinker511d ago
Call AddSource on the context inside RegisterSourceOutput although actually... i don't know if you can output things other than cs files Better ask in #roslyn to be safe
A
Accord510d ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ Making an async method without anything to async insidelet's say i have following scenario: ```csharp void Foo() { for(int i = 0 ; i < 10000000 ;i++){} /❔ Reading file from the folder where .csproj isHow can i read files from folder where .csproj is? just like webapps allow to do, they do not copy f✅ Interoperability between incompatible typesHi! I'm trying to pass a class back-and-forth from C# to CPP. This class contains some members that ❔ Set item to null inside a listHey! I am trying to remove some items from a JSON object (created like `var model = new ObjectModel{Refactoring long if statement that checks for user rolesHi, I'm trying to find a cleaner way of refactoring this if code block that checks for each user rol❔ IEnumerable and dependency injectionif i want to loop enumerable from DI multiple times ``` var foos = services.GetRequiredService<IEnum❔ How did you learn . NET ?Books /youtube/udemy /other courses, what resources made you learn .NET to use as your job as web de✅ Is it possible to disable these properties on EF6? Web API 2 project, multi-layered, NF472SCENARIO - Solution type is NET Framework 4.7.2 (it is, what it is). - I have this project, I'm cons✅ This EntityFramework query can not be translated for SQLiteThe issue lies within `Intersect`. The point of the query is to fetch the current user, and to popul✅ Detect Network RequestI want make service that detect all connection to specific domain or ip? And if this request contain❔ CORS errorHello, I have Cors error on my project. I add Addpolicy in my configureServices and also add app.Us❔ Ambiguities? How?Idk how i can resolve this i don't see the problem✅ How can I get rid of this annoying pointer thing in the first row, datagridview winforms^✅ How can I use a row header of a datagridview to display the row number instead of being empty?^✅ How can i properly display this datagridviewHow can i get rid of the row select thing on the left (just white space)✅ I am trying to output a 2D array to a datagridview, but it is not outputting correctlyIt is saying System.Int32[]✅ Task not returning and stopping programHey, I am currently trying to start one task for every string in the list, but this isn't working an❔ DbContextCan i use this in a non-asp area like for example, a simple program to make few tables using DbSet✅ The specified deps.json does not exist while scaffolding DBI am going through a tutorial to create a Web API app with ASP.NET6 and MySql. I wanted to scaffold ❔ C sharp object reference errorI am trying to reference an object that I'm displaying on PageHeader.xaml and I keep getting this er