icsharpcode / ILSpy

.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
21.35k stars 3.34k forks source link

C# decompilation of indexed property is misleading #1089

Open carlreinke opened 6 years ago

carlreinke commented 6 years ago

The navigation tree gives a good hint that it's an indexed property, but if you're using ILSpy inside Visual Studio then the tree doesn't show and you only get the the C# code, which doesn't have any indication.

Here's how it looks in ILSpy: envdte-ilspy

Here's how Visual Studio 2017 shows it with ILSpy turned off: envdte-vs2017

Here's how Visual Studio 2017 shows it with ILSpy turned on: envdte-vs2017-ilspy

dgrunwald commented 6 years ago

Hmm, not sure how we could display an indexed property in C# syntax. We could ignore the property and display the accessor methods instead (like the VS metadata view does), but then we're missing out on the property attributes. Or we could display the parameter list somehow, maybe as a code comment: new CodeElement CodeElement/*[vsCMElement]*/

svick commented 6 years ago

Since indexers and indexed properties are almost the same thing in IL, maybe some variation of the syntax for indexers could work?

E.g.:

[DispId(51)]
[IndexerName("CodeElement)"]
public EnvDTE.CodeElement this[EnvDTE.vsCMElement Scope] /* indexed property */
{
    [DispId(51)]
    get;
}
siegfriedpammer commented 6 years ago

Using indexer declaration syntax is not possible, because that would declare it as default property on recompilation. Also all use sites of the property would have to use indexer syntax, which does not really work... Currently method declaration syntax plus a comment adding the property attributes seems to be the only sensible way to solve this.