How the C# 14 field keyword decompiles
The field keyword reuses the same <Name>k__BackingField an auto-property emits, so the metadata is identical. The decision to render field lives entirely in the accessor IL. Here is how Glass.NET reads it back.
C# 14 added the field contextual keyword: inside a property accessor you can now write field to reach the compiler-synthesized backing field without declaring it yourself. It turns the common “auto-property, but with a little validation” pattern from a two-member chore — a private field plus a full property — into a single property whose accessors do their work and then read or write field. It is a small feature with an outsized effect on everyday code, and it is already spreading fast.
It is also a genuinely interesting decompilation problem, because field is invisible in metadata. The backing field it reuses is the very same <Name>k__BackingField that a plain auto-property emits, carrying the very same [CompilerGenerated] marker. There is no new attribute, no flag, nothing in the Property table that records “this property used field.” The entire difference between { get; set; } and a field-using property lives in one place: the bodies of the accessor methods. A decompiler that reads the field and the property rows learns nothing; it has to read the IL of get_ and set_ and decide, per accessor, whether what it sees is a trivial passthrough or real work.
This post shows the identical metadata the two constructs share, the three accessor shapes that force the decision one way or the other, and how Glass.NET reconstructs each.
The two constructs that share one metadata shape
Here is a plain auto-property and a field-keyword property whose accessors happen to be trivial:
// Plain auto-property
public string A { get; set; }
// field keyword, but the accessors do nothing extra
public string B { get => field; set => field = value; }
Both compile to the same three pieces of metadata: a private backing field, a get_ accessor, and a set_ accessor. The field for A:
.field private string '<A>k__BackingField'
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor()
= ( 01 00 00 00 )
The field for B is identical but for the name, '<B>k__BackingField'. Same visibility, same [CompilerGenerated], same everything. And the accessor bodies are identical too — the getter for both is a bare load, the setter a bare store:
.method public hidebysig specialname instance string get_A () cil managed
{
.custom instance void [...]CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
ldarg.0
ldfld string C::'<A>k__BackingField'
ret
}
.method public hidebysig specialname instance void set_A (string 'value') cil managed
{
.custom instance void [...]CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
ldarg.0
ldarg.1
stfld string C::'<A>k__BackingField'
ret
}
This is the crucial fact: get => field; set => field = value; and { get; set; } are the same program. The compiler emits byte-for-byte identical IL. There is nothing for a decompiler to recover, because there is nothing to distinguish — and so the right answer is the simpler one. Glass renders both as { get; set; }. Reproducing B’s source literally would be noise; the two forms are interchangeable and the auto-property is what every reader expects.
The decompiler recognises the passthrough by shape. The getter must be exactly ldarg.0; ldfld <backing>; ret, the setter exactly ldarg.0; ldarg.1; stfld <backing>; ret, and the field must be the compiler-generated <Name>k__BackingField referenced by nothing but these two accessors. Match all of that and you have a true auto-property, whatever syntax produced it.
A setter that does work: the field keyword is forced
Now break the passthrough on the set side — the single most common reason to reach for field:
public string Name
{
get => field;
set => field = value ?? string.Empty;
}
The getter is still a passthrough, but the setter now runs the null-coalescing operator before it stores. That ?? string.Empty lowers to the standard dup / brtrue / pop sequence:
.method public hidebysig specialname instance void set_Name (string 'value') cil managed
{
ldarg.0
ldarg.1
dup
brtrue.s IL_000a
pop
ldsfld string [System.Runtime]System.String::Empty
IL_000a:
stfld string Person::'<Name>k__BackingField'
ret
}
Read the stack: ldarg.0 puts this down for the eventual stfld; ldarg.1 loads value; dup copies it; brtrue.s keeps the copy if it is non-null and jumps to the store; otherwise pop discards the null and ldsfld String::Empty substitutes the empty string. Either way the value on the stack is stored into the backing field. This is unmistakably not the two-instruction passthrough, so the auto-property collapse is off the table.
That leaves the decompiler with a problem that only C# 14 can solve cleanly. The backing field is named <Name>k__BackingField, and those angle brackets make it an unspeakable name — a name the compiler reserves so that no source identifier can ever collide with it. You cannot type it. Before the field keyword existed, a decompiler here had to invent a private field with a legal name and rewrite both accessors to use it, turning a one-line property into a field plus a full property and changing the shape of the type. Now the reconstruction is exact:
public string Name
{
get => field;
set => field = value ?? string.Empty;
}
Glass renders the trivial getter as get => field; (it could equally be elided, but keeping it explicit mirrors the real accessor) and the real setter with field standing in for the synthesized store. The output compiles back to the identical IL.
A getter that does work: the asymmetric case
The decision is per accessor, not per property, so the mirror image is just as valid — a trivial setter and a getter that computes:
public string Display
{
get => field ?? "(unset)";
set => field = value;
}
Here the setter is a bare passthrough but the getter runs ?? "(unset)":
.method public hidebysig specialname instance string get_Display () cil managed
{
ldarg.0
ldfld string Person::'<Display>k__BackingField'
dup
brtrue.s IL_000b
pop
ldstr "(unset)"
IL_000b:
ret
}
Same dup / brtrue / pop pattern, this time substituting a literal when the stored value is null. Because one accessor does work, the property cannot collapse to { get; set; } — rendering it that way would silently drop the default. Glass surfaces the getter with field and leaves the setter trivial:
public string Display
{
get => field ?? "(unset)";
set => field = value;
}
The same reasoning extends to lazy initialization — public Cache C => field ??= new(); — where the getter’s ??= compound-assign reads, tests, constructs and stores through field, and the property has no setter at all. The shape of the IL differs, but the rule Glass applies is the one constant across every case: find the compiler-generated backing field, test each accessor against the passthrough template, and render field for any accessor that fails the test.
Reading one back with Glass
Because the whole decision rides on accessor IL, the IL view is the quickest way to confirm what a property really does. Point Glass at the assembly and dump the property:
$ glass export ./People.dll --member "P:Person.Name" --il
That prints the backing field, both accessor bodies, and the MethodSemantics links, so you can see for yourself whether an accessor is a passthrough or does work before touching <Name>k__BackingField. Drop --il and Glass reconstructs the C#:
$ glass export ./People.dll --member "P:Person.Name"
public string Name
{
get => field;
set => field = value ?? string.Empty;
}
You get the identical result in the app’s side-by-side view — select the property and the IL pane shows the accessor bodies next to the reconstructed source, so the passthrough test the decompiler just made is right there to check by eye. Glass uses the same ICSharpCode.Decompiler engine in the CLI and the UI, and everything is static: it reads the metadata and the IL and reconstructs the source. It never runs the accessors, which is exactly why it is safe to point at a dependency you are still deciding whether to trust.
The field keyword is going to be everywhere, because it removes the one friction point that kept people writing full backing-field properties. Knowing that it leaves no metadata fingerprint — that a decompiler recovers it purely from the shape of the accessor body — is worth having the next time you are reading how a library validates a property you are passing data into, or debugging why your own setter normalised a value you did not expect. Grab the latest build from the Glass.NET download page and read the next field you meet.
Try Nebula.NET
Harden your .NET code in minutes — start with the free edition.