C#
C#

help

Root Question Message

CrosRoad95
CrosRoad9512/10/2022
❔ 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?
CrosRoad95
CrosRoad9512/10/2022
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
AntonC
AntonC12/10/2022
You probably want swagger and NSwag if you're doing a rest api
CrosRoad95
CrosRoad9512/10/2022
not rest api
CrosRoad95
CrosRoad9512/10/2022
just plain text file with typescript definition
thinker227
thinker22712/10/2022
An SG can output non-cs source files afaik.
AntonC
AntonC12/10/2022
And if you're doing grpc, you just need to use their compiler
CrosRoad95
CrosRoad9512/10/2022
^ thats what i want
CrosRoad95
CrosRoad9512/10/2022
i already use grpc lib for it
AntonC
AntonC12/10/2022
well it supports generating clients for different languages
CrosRoad95
CrosRoad9512/10/2022
class Foo{ void Bar(){} }
do some reflection magic, generate:
interface Foo {
  bar(): void
}
thinker227
thinker22712/10/2022
Are you talking about SGs or reflection
AntonC
AntonC12/10/2022
what's your use case
CrosRoad95
CrosRoad9512/10/2022
generate typescript types from c# classes
CrosRoad95
CrosRoad9512/10/2022
is it able to read comments?
thinker227
thinker22712/10/2022
yes
CrosRoad95
CrosRoad9512/10/2022
ok, i will try it then
AntonC
AntonC12/10/2022
what for
CrosRoad95
CrosRoad9512/10/2022
did they fix so i no longer need to restart vs to see new generated code?
thinker227
thinker22712/10/2022
nope
thinker227
thinker22712/10/2022
Also, you might want to consider using an attribute to denote the types which should be targeted
CrosRoad95
CrosRoad9512/10/2022
i'm using ClearScript tags to do it
CrosRoad95
CrosRoad9512/10/2022
attributes* not tags
CrosRoad95
CrosRoad9512/10/2022
how can i tell an IIncrementalGenerator to generate content, for example html files?
CrosRoad95
CrosRoad9512/10/2022
Generator attribute doesn't like "Html" as first parameter
thinker227
thinker22712/10/2022
Call AddSource on the context inside RegisterSourceOutput
thinker227
thinker22712/10/2022
although actually... i don't know if you can output things other than cs files
thinker227
thinker22712/10/2022
Better ask in #598678594750775301 to be safe
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy