Implement A Class's Declared Interface Through A Primary Constructor Parameter Object (Generate Boilerplate Implicitly) #9815
Unanswered
steevcoco
asked this question in
Language Ideas
Replies: 2 comments
-
|
Can be done with a source generator using specific rules you define. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It seems possible that the compiler could generate code for an interface implementation, by delegating to a primary constructor's parameter with that type.
For example:
`
public interface IPartial
{
string Name { get; }
}
public class NamedList(IList list, string name)
: IList from list,
IPartial
{
public string Name
=> name;
}
`
Since the Type of the constructor's IList parameter is known, then a "boilerplate" interface implementation of IList could be generated that simply invokes the given object.
Beta Was this translation helpful? Give feedback.
All reactions