[Feature request] Dynamic Interfaces #2290
Replies: 5 comments
-
I think #110 (shapes) would cover this. |
Beta Was this translation helpful? Give feedback.
-
I don't see why this needs to be a language feature. You can use a library like like ImpromptuInterface instead: var iSuppContact = supplier.ActLike<IContact>(); ImpromptuInterface does not throw an exception from |
Beta Was this translation helpful? Give feedback.
-
@svick Yes, this approach can be used; the benefit of having this as a language feature is having compile time checks; the code won't compile until the classes matches the interface. |
Beta Was this translation helpful? Give feedback.
-
@MHanafy That sounds like something that could be done with a Roslyn analyzer. |
Beta Was this translation helpful? Give feedback.
-
That's exactly what Shapes are all about. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When working on large codebases, sometimes there's a need to work on a large set of classes that all shares a common set of properties.
The typical solution is, to create a new interface, and make all these classes implement it; then refer to them through the interface.
While this's sometimes doable, the larger the codebase the harder it's to do.
I'm thinking about a simple solution, where C# allows a dynamic interface; then when using type comparison/casting to a dynamic interface; the class simply needs to match the interface members without a need to change the original class.
This will be very useful in maintaining large, long running projects that has a lot of classes.
Beta Was this translation helpful? Give feedback.
All reactions