-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Exclude individual properties from the "Wither" #101
Comments
@bboyle1234 I can't think of such a scenario. Why would just having the |
Because as far as I understand the question, everything would be as is, just the selected property's With method wouldn't be generated. Am I right? |
Yes, you're right. public sealed class StockPriceUpdate {
[SuppressWith] public string Symbol { get; }
public decimal Price { get; }
} |
Currently, it doesn't make sense (the request): there are other ways to instantiate the copy with symbol changed, e.g. constructor, builder, Update method. A comment should pass the intent "enough". In this scenario, the class isn't really a record: It has some constraints that disqualify it, like disallowing mutation of some property. You'd also probably want to hide the constructor as In terms of benefitting from |
Yes. It's very tempting to limit the scope of this project to "just records" because that's a lot narrower and simpler. But what we all really need is a library that allows us to write flexible immutable classes. |
It would be really cool if this project would allow setting the I've seen this done in AArnott's Other things I really liked from that library were the ability to pre-calculate the hashcode just once, in the constructor, and I especially like the convention of using readonly fields instead of readonly properties. That's because when writing immutable objects, we often don't want to expose all the readonly fields as public properties, or we want to expose properties that are formed differently from the underlying readonly fields. |
I'm lazy. Can you summarize how it was done?
I'm a strong supporter of properties, because they offer a much better extensibility approach, are more concise, were designed for publicly exposing "data" members (not methods) and have superior tooling support in a staggering number of scenarios. Fields are much simpler indeed. That'd be their only advantage.
That might be true, but in that case - most of this library's features are useless. What's left? Constructor? How would Builders or Withers work if there's no ctor params <-> backing fields <-> properties parity? Equality is a recent addition, and I'm more and more convinced it should be extracted into a separate library. It's undeniably useful, and in more scenarios than records are. "Primary" constructor would be another candidate, so it'd fulfill the need for a more customizable feature set, like accessibility, additional extension points, readonly fields support, etc. |
Some immutable objects need to be able to exclude certain properties from the "Withing" feature.
Can there be an attribute added to a property that excludes it from the generation of With updaters?
The text was updated successfully, but these errors were encountered: