Automatically generate IEquatable, IEqualityComparer, IComparable, toString for "simple" classes. #550
-
Like Haskell’s |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments
-
That's planned for records. Well, not |
Beta Was this translation helpful? Give feedback.
-
O i forgot |
Beta Was this translation helpful? Give feedback.
-
Does there need to be syntax for this? Templates, code snippets and right clicking the interface name in the class declaration already do a great job. When you want to hide the implementation, just put them in a collapsible |
Beta Was this translation helpful? Give feedback.
-
I'm afraid that's not acceptable at all. Since the problem with generating the code is that the generated code risks falling out of sync with the rest of the class I'd say that hiding the implementation in a region will only exacerbate the issue. Hopefully at least some of this will be solved when we eventually get default interface methods #406, and at least we will 'inherit' |
Beta Was this translation helpful? Give feedback.
-
Good use case for a build-time analyzer, btw. |
Beta Was this translation helpful? Give feedback.
-
I've heard that so often now "build an analyzer". It would be nice if there were some kind of IDE help for this, e.g. a GUI, an Analyzer Wizard or an easy config file that could define those analyzers without diving into building a dedicated dll by self written analyzer code. |
Beta Was this translation helpful? Give feedback.
-
@lachbaer I agree. Plus, the templates are so far out of date it's embarrassing. dotnet/project-system#1481 |
Beta Was this translation helpful? Give feedback.
-
@jnm2 you haven't tried to build a JIRA plugin recently. Their project templates are even worse. They contain not just outdated, but semantically invalid code. |
Beta Was this translation helpful? Give feedback.
-
@orthoxerox I'm sorry! I'm not likely to either, now that you told me that. |
Beta Was this translation helpful? Give feedback.
-
There are still several unanswered questions, but I thoroughly support generation of at least Equality and ToString methods by the compiler through use of an attribute, as has been approved in principal for F# fsharp/fslang-suggestions#554 |
Beta Was this translation helpful? Give feedback.
-
Again a good use for an analyzer. Mark every method with an attribute where the analyzer should check if all fields (maybe restricted to visibility) are somehow referenced. When you add a field you will get a warning or error and you can fix that appropriately. For standard methods an automated codefix can help you. Having that written, I think that there should be much more documentation on analyzers and code fixes (what else?) on the net and in every new upcoming book on the shelves! |
Beta Was this translation helpful? Give feedback.
-
I think this can be considered covered between records and source generators |
Beta Was this translation helpful? Give feedback.
I think this can be considered covered between records and source generators