Target-typed interfaces in anonymous types #7893
-
Anonymous types add a lot of convenience when you just want an ad-hoc type quickly. Allowing anonymous types to meet interface criteria based on the target of the type, sounds like a nice convenience. M(new { Context = "" }); // this could be made work
void M(I i) { }
public interface I
{
string Context { get; }
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Beta Was this translation helpful? Give feedback.
-
This already works, so doesn't require a language change, and does exactly what you want in fewer lines of code: M(new(Context = "" ));
void M(R r) { }
public record R(string Context); |
Beta Was this translation helpful? Give feedback.
-
I'll take your word for it 😃 |
Beta Was this translation helpful? Give feedback.
#4301
#7719
#7726