Replies: 1 comment 2 replies
-
IL allows you to have a property and a method that has the same name. C# does not. The anonymous class feature of the compiler is taking advantage of features that you're not permitted to use directly. While it's probably a bit pathological to name the elements of an anonymous type after the methods of |
Beta Was this translation helpful? Give feedback.
2 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.
-
I found out, that roslyn does allow that anonymous types have properties of inherited member names like:
Is this required to work?

If you paste this code for example in a VisualStudio installation with ReSharper installed you get red squiggles:
If you apply the Resharper-Reforctoring "Anonymous to Named type", you get the following result:
Unfortunately this code does not compile. Mainly because of
Why does the overrides conflicts with the properties?
If you take a look into the generated IL Code produced by Roslyn (e.g. with ILSpy) the code looks very similar.
On the other hand if you split the anonymous type in two classes it is possible to define something similar (simplified - just implementing
Equals
):Beta Was this translation helpful? Give feedback.
All reactions