Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override type generation #12

Open
Psvensso opened this issue Sep 23, 2018 · 5 comments
Open

Override type generation #12

Psvensso opened this issue Sep 23, 2018 · 5 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Psvensso
Copy link

When sending data from a backend service to the client the data is in many cases converted to JSON. Complex data types such as DateTime is serialized into strings.

Therefor it would be a much needed feature to be able to override the output type in the generator, so that in this example the DateTime becomes strings. Otherwise the TS interfaces would need a concrete class implementation to be useful (someone that creates a new Date() from the JSON).

One way to solve this, and this is indeed how we solves it now in my project, is to simple let the date times be strings on the C# end as well and then we parse them manually. But this could be done all by magic by the JSON serializer.

Suggestion:
Imlement a overide feature that take From>To type by config that is valid for all types in folder.
Or a To type in a data annotation.

@Psvensso
Copy link
Author

I started to look at this but i can't get my fork to run on my machine.
The build can't access Microsoft.CodeAnalysis.CSharp even though it's clearly there and everything is restore properly. (I'm on a win 10 machine with VS2017 pro).

I might have a look later in the week.

But please respond if guys this this is even a viable feature req.

@CodySchrank
Copy link
Owner

I understand the need but currently any kind of type annotation is not feasible because the code is not compiled.

I've been considering compiling the c# to use reflection so if I do then this could be added.

@CodySchrank CodySchrank self-assigned this Sep 24, 2018
@CodySchrank CodySchrank added the enhancement New feature or request label Sep 24, 2018
@CodySchrank
Copy link
Owner

I started to look at this but i can't get my fork to run on my machine.
The build can't access Microsoft.CodeAnalysis.CSharp even though it's clearly there and everything is restore properly. (I'm on a win 10 machine with VS2017 pro).

I might have a look later in the week.

But please respond if guys this this is even a viable feature req.

That was an experimental build that accidently got pushed to main. MTT doesn't actually use code analysis so I removed the references, you should now be able to restore and build the project.

@CodySchrank CodySchrank added the reflection Only possible with reflection label Sep 24, 2018
@wmwood
Copy link

wmwood commented Dec 10, 2019

I'd also love this.

It's more of a preferential thing but I'd prefer that my Guid's come down as string in TS.

Like I said it's a personal bias so being able to override that would be a nice to have.

@CodySchrank
Copy link
Owner

I played around with this idea back when the issue was created and it seemed like the best approach would be using type annotations. However the code is not compiled so those annotations would have to be parsed somehow, without losing what field is supposed to be overridden and what its supposed to be overridden with. It seemed like it could get messy so I never bothered, but someone is more than welcome to add this in a PR and I would approve if it doesn't break anything.

@CodySchrank CodySchrank added help wanted Extra attention is needed and removed reflection Only possible with reflection labels Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants