Anonymous types should implement the interface they are assigned to #1542
Replies: 11 comments
-
Anonymous types in C# are readonly. I could possibly see this working if the properties were declared as readonly also, but I'd prefer a more explicit syntax for creating the anonymous type, e.g. |
Beta Was this translation helpful? Give feedback.
-
Similar: #100 |
Beta Was this translation helpful? Give feedback.
-
#100 seems to be dealing with omitting the type in a |
Beta Was this translation helpful? Give feedback.
-
Ah ya, that looks like a superset of what I'm asking for here. I'm certainly not asking to implement interfaces with methods on them. But the response to it doesn't bode well for this smaller) request. |
Beta Was this translation helpful? Give feedback.
-
@AArnott Right, but #100 gives the caller a similar syntax to work with. It is still more work on the definition side. |
Beta Was this translation helpful? Give feedback.
-
It's still something happening with this? @AArnott @gafter In #100 you should provide an implementation to can use the I find this construct |
Beta Was this translation helpful? Give feedback.
-
@glucaci You are asking for dotnet/roslyn#13 (comment):
|
Beta Was this translation helpful? Give feedback.
-
@jnm2 yes, thanks for pointing that. |
Beta Was this translation helpful? Give feedback.
-
Following @MadsTorgersen dotnet/roslyn#13 (comment)
maybe we can have a more recent update about what he is thinking on this topic. Pointing to local classes (dotnet/roslyn#13 (comment)) has nothing to do with this request because than is useless, I can declare a class anywhere else and use it. |
Beta Was this translation helpful? Give feedback.
-
I suspect it is unlikely he has thought about it since then. |
Beta Was this translation helpful? Give feedback.
-
It's almost like duck-typing, but still strongly typed. When I create an anonymous type that the C# compiler can see must implement a particular interface in order to compile, the generated anonymous type should implement that interface implicitly.
For example, this should compile:
Beta Was this translation helpful? Give feedback.
All reactions