Write row[5] in C# and it looks like array access. It is not. The type behind it defined an indexer — public double this[int column] — and the compiler turned that into something with no bracket syntax anywhere in sight: an ordinary method call. Worse, the name the brackets stand for isn't even in the call. To put the this[…] back, a decompiler has to read three separate pieces of metadata and prove they belong together. This post walks one indexer all the way down to IL and metadata and back up to C#, and shows the exact rule Glass.NET, the free .NET decompiler, uses to recover it.

The real question

An indexer feels like a language primitive, but the CLR has no notion of one. Properties, methods, fields — those are real metadata tables. "Indexer" is a C# fiction layered on top of a parameterized property. So the question is: given a compiled type, how do you know that a particular property is meant to be written x[i] rather than x.Item[i], and how do you turn the method calls at every use site back into brackets? The answer is a small, honest pattern match over three facts, and it degrades gracefully when any of them is missing.

The source

A sparse row that stores only non-zero cells, exposed through an indexer:

public sealed class SparseRow { private readonly Dictionary<int, double> _cells = new(); public double this[int column] { get => _cells.TryGetValue(column, out var v) ? v : 0d; set => _cells[column] = value; } } 

And a use site that reads two cells:

double total = row[0] + row[5]; 

Nothing here mentions a name for the indexer. In the source there is only this. That matters, because the compiler has to invent a name to hang the metadata on.

What the compiler emits

Three artifacts appear in the assembly, and the indexer only exists as the combination of all three.

First, a parameterized property. The CLR property table normally holds nullary properties — a getter and/or setter with no parameters. An indexer is encoded as a property whose signature carries parameters. By default the compiler names it Item:

.property instance float64 Item(int32) { .get instance float64 SparseRow::get_Item(int32) .set instance void SparseRow::set_Item(int32, float64) } 

Second, the accessor methods. get_Item and set_Item are real methods, marked specialname so tools know they back a property rather than being callable as row.get_Item(0) from C#:

.method public hidebysig specialname instance float64 get_Item (int32 column) cil managed { // _cells.TryGetValue(column, out v) ? v : 0.0 } .method public hidebysig specialname instance void set_Item (int32 column, float64 'value') cil managed { // _cells[column] = value } 

Third — and this is the piece most people forget — a DefaultMemberAttribute on the type that records which member name is the indexer:

.custom instance void [System.Runtime]System.Reflection.DefaultMemberAttribute::.ctor(string) = (01 00 04 49 74 65 6d 00 00) // "Item" 

Those bytes decode as the serialized-attribute prolog 01 00, a length 04, the UTF-8 string 49 74 65 6d = Item, and the trailing 00 00 for zero named arguments. This attribute is what typeof(SparseRow).GetDefaultMembers() reads at runtime, and it is the keystone for reconstruction: it says "the property called Item is the one that gets bracket syntax."

At the use site, the brackets are gone entirely — each read is just a virtual call to the getter:

IL_0001: ldloc.0 // row IL_0002: ldc.i4.0 IL_0003: callvirt instance float64 SparseRow::get_Item(int32) IL_0008: ldloc.0 // row IL_0009: ldc.i4.5 IL_000a: callvirt instance float64 SparseRow::get_Item(int32) IL_000f: add 

A write would be the mirror image: push the receiver, the index, the value, then callvirt set_Item(int32, float64).

The pattern Glass keys on

Glass does not guess from the method name. get_Item is a convention, not a guarantee — as we'll see, IndexerName can change it. Instead it joins the property, its accessors, and the type's DefaultMemberAttribute into one decision:




The indexer is a fiction reassembled from a parameterized property, its special-name accessors, and the type-level DefaultMemberAttribute that names it.

Stated precisely, the rule is: a property whose signature declares one or more parameters, and whose name matches the string in the type's DefaultMemberAttribute, is rendered as this[…]. The property's parameter list becomes the bracket parameter list; its getter and setter become the get/set accessors. Then every callvirt/call to those accessor methods at a use site collapses back to bracket syntax: get_Item(i) becomes x[i], and set_Item(i, v) becomes x[i] = v.

What Glass reconstructs

Run it through the decompiler:

glass decompile SparseRow.dll --type SparseRow 

Glass produces the original declaration — brackets, not Item:

public sealed class SparseRow { private readonly Dictionary<int, double> _cells = new(); public double this[int column] { get => _cells.TryGetValue(column, out double v) ? v : 0.0; set => _cells[column] = value; } } 

and the use site comes back as row[0] + row[5], with no trace of get_Item anywhere. The three metadata facts have fused back into the single piece of syntax the programmer actually wrote.

When you want to see the raw shape

Because recognition is a pattern, Glass can turn it off so you can audit what the compiler really emitted — useful when you are reading your own release build with no PDB and want to confirm an index access is a plain accessor call and not something wrapped around it:

glass decompile SparseRow.dll --member get_Item --no-pattern indexer 
// raw: the accessor is shown as the method it really is public double get_Item(int column) => _cells.TryGetValue(column, out double v) ? v : 0.0; 

IndexerName: when the accessors aren't called get_Item

The accessor base name is not fixed. Apply [IndexerName("Chars")] and the compiler emits get_Chars/set_Chars and sets DefaultMemberAttribute("Chars") — this is exactly how System.String exposes s[i] through methods named get_Chars. The point of the attribute is that the runtime name is decoupled from the this syntax.

Glass handles this the honest way. Because its match test compares the property name to the DefaultMember string rather than hard-coding "Item", a renamed indexer still reconstructs as this[…]. And because the chosen name is observable through reflection, Glass re-emits the attribute whenever the indexer name is not the default, so the recompiled source behaves identically:

[IndexerName("Chars")] public char this[int index] => _text[index]; 

Drop that attribute and callers using reflection by name would break — so preserving it is part of a faithful decompile, not cosmetic.

Caveats and the edges

  • Overloaded indexers. this[int] and this[string] both live under one DefaultMemberAttribute("Item"); the assembly holds two parameterized Item property rows distinguished only by signature. Glass keys on the full signature, not the name, so both come back as separate this[…] overloads.
  • Explicit interface indexers. double IReadOnlyList<double>.this[int] is emitted as a property whose name is the mangled System.Collections.Generic.IReadOnlyList<System.Double>.Item. It is not listed in the type's DefaultMemberAttribute (that applies to the public surface). Glass recognizes the interface-qualified property name and reconstructs the explicit-interface indexer form.
  • A parameterized property that is not the default member. Some languages (notably VB.NET) can emit a parameterized property that the type does not nominate as its default. With no matching DefaultMemberAttribute, Glass will not fake this[…]; it shows the property as what it is, because pretending otherwise would misrepresent how C# callers must access it.

Takeaway

An indexer is one of the clearest examples of a C# feature that exists only as a convention stitched across several metadata tables: a parameterized property, special-name accessor methods, and a type-level attribute that ties them to bracket syntax. A decompiler that only looked at method names, or only at the property table, would get it subtly wrong — miss the IndexerName, mangle the explicit-interface case, or invent brackets where a language never meant any. Glass joins all three facts and falls back to the literal form when they don't agree.

Glass.NET is a free, static-only decompiler for exactly this kind of reading — your own assemblies, your dependencies, your legacy builds. It reads IL and metadata to C#; it never runs, patches, or modifies the code. Point it at a DLL in the Visual-Studio-native UI, the CLI, or over MCP, and this[…] comes back wherever the metadata says it belongs.