❔ 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?
19 Replies
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
You probably want swagger and NSwag if you're doing a rest api
not rest api
just plain text file with typescript definition
An SG can output non-cs source files afaik.
And if you're doing grpc, you just need to use their compiler
^ thats what i want
i already use grpc lib for it
well it supports generating clients for different languages
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:
Are you talking about SGs or reflection
what's your use case
generate typescript types from c# classes
is it able to read comments?
yes
ok, i will try it then
what for
did they fix so i no longer need to restart vs to see new generated code?
nope
Also, you might want to consider using an attribute to denote the types which should be targeted
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
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 safeWas 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.