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

Idea: Source Generator for New types #804

Open
bash opened this issue Jan 14, 2025 · 0 comments
Open

Idea: Source Generator for New types #804

bash opened this issue Jan 14, 2025 · 0 comments
Labels
to discuss There are open points which need to be discussed

Comments

@bash
Copy link
Member

bash commented Jan 14, 2025

I want to write another source generator while following along this guide :) And since I have wanted to replace our reflection-based NewType converter with a source-generated one I thought a general new type generator would be fun.

What features should it have?

Off the top of my head:

  • generate a JSON converter (and point to it via the [JsonConverter] attribute)
  • replace the record's ToString() implementation with a more tuple-like representation
    so instead of DisplayName { Value = test } we should get DisplayName(test).
  • delegate comparable operators <=, >=, > and <.
  • delegate interface implementations? this one seems like a lot of hassle (especially for things like IComparable where other is an object that we need to "unpack" the value first before delegating).
    Maybe we start with a list of known interfaces (e.g. IComparable<T>, IComparable) first.

I think it's also OK to restrict the source generator to sealed class record / record structs with primary constructors for now.

@bash bash added the to discuss There are open points which need to be discussed label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to discuss There are open points which need to be discussed
Projects
None yet
Development

No branches or pull requests

1 participant