Replies: 2 comments 7 replies
-
This should be possible with a Roslyn Analyzer. I think it'd be relatively straightforward too. Find the generic type used, find the ctors of that type, and warn if there's a mismatch. |
Beta Was this translation helpful? Give feedback.
0 replies
-
@KennethHoff I cannot imagine how it should work for intellisense suggestions which would be almost the whole point of such a feature. |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Firstly, I'd like to apologize if this isn't the appropriate forum for this kind of feature proposal. If there's a more suitable venue for this discussion, please let me know.
Proposal:
Constructor redirect
Summary:
Allow for constructor arguments to be seemingly mirrored by a generic factory method.
Sample:
Alternatives:
Source Generators:
a source generator could be written to archive this goal, but source generators do not fully support method signature changes. (They do support it but visual studio does not update the generated code when the signature changes)
Generic Factory:
a generic factory could be written (like the one above, but without attributes) but this would require the developer to know the constructor parameters of the type they are trying to create.
Manually Implementing the factory for each type:
this is the current solution, but it requires a lot of boilerplate code to be written for each type that needs to be created.
Motivation:
Having a factory method that can create instances of a type is already possible.
Now, with intellisense support, it would be possible to create instances of a type without having to know the constructor parameters.
Beta Was this translation helpful? Give feedback.
All reactions