Why decompilers show LINQ as method calls
Query syntax is the one C# feature that lowers to other C# source before it ever reaches IL: from/where/select is rewritten into .Where(...).Select(...) by a purely textual transformation, so no attribute or flag records that you ever wrote a query. Here is the exact clause-to-method mapping, the IL it produces, the transparent-identifier anonymous type that a let clause leaves behind, and how Glass.NET reconstructs the chain.
You write a tidy query expression:
IEnumerable<string> Adults(IEnumerable<Person> people) =>
from p in people
where p.Age >= 18
select p.Name;
You decompile the assembly and get this back:
IEnumerable<string> Adults(IEnumerable<Person> people) =>
people.Where(p => p.Age >= 18).Select(p => p.Name);
The from, the where, the select — all gone. This is not a decompiler cutting a corner. It is the single most complete erasure in the C# language, and understanding it tells you something precise about what a decompiler can and cannot recover.
The one feature that lowers to source
Almost every C# feature lowers to IL. async, iterators, lambdas, pattern matching — each becomes some specific shape of bytecode, metadata, and synthesized types. Query expressions are different. They are the only construct the specification defines as a rewrite into other C# source (§12.20, “Query expressions”). Before the compiler binds a single method, it textually translates the query into a tree of invocation expressions, and from that point on the query syntax simply does not exist.
The translation is mechanical and documented. Each clause maps to a method call by name:
from p in people → people (the source)
where f → .Where(p => f)
select v → .Select(p => v)
orderby k → .OrderBy(p => k)
orderby k descending → .OrderByDescending(p => k)
, then by k2 → .ThenBy(p => k2)
let y = f → .Select(p => new { p, y = f })
from q in e2 → .SelectMany(p => e2, (p, q) => ...)
group v by k → .GroupBy(p => k, p => v)
join ... into g → .GroupJoin(...)
Notice what the compiler does not do here: it does not look up System.Linq.Enumerable. The query translation is pattern-based and duck-typed. It emits a method-group call named Where, and only afterwards does ordinary overload resolution decide which Where that is — Enumerable.Where for an IEnumerable<T>, Queryable.Where for an IQueryable<T>, or a Where you wrote yourself on your own type. The query form carries no allegiance to LINQ; it is sugar for method calls whose meaning is resolved like any other call.
What reaches the IL
After the rewrite, the lambdas lower the way all lambdas do. A lambda that captures nothing becomes a cached static delegate, created once and reused. So the two query clauses above compile to this:
IL_0000: ldarg.1
IL_0001: ldsfld class Func`2<Person,bool> C/'<>c'::'<>9__0_0'
IL_0006: dup
IL_0007: brtrue.s IL_001c
IL_0009: pop
IL_000a: ldsfld class C/'<>c' C/'<>c'::'<>9'
IL_000f: ldftn instance bool C/'<>c'::'<Adults>b__0_0'(class Person)
IL_0015: newobj instance void Func`2<Person,bool>::.ctor(object, native int)
IL_001a: dup
IL_001b: stsfld class Func`2<Person,bool> C/'<>c'::'<>9__0_0'
IL_001c: call !!0 [System.Linq]Enumerable::Where<Person>(IEnumerable`1<!!0>, Func`2<!!0,bool>)
IL_0021: ldsfld class Func`2<Person,string> C/'<>c'::'<>9__0_1'
// ... identical cache-or-create dance ...
IL_003c: call !!1 [System.Linq]Enumerable::Select<Person,string>(IEnumerable`1<!!0>, Func`2<!!0,!!1>)
IL_0041: ret
Two call instructions to Enumerable::Where and Enumerable::Select, two cached Func delegates. There is no QueryExpressionAttribute, no flag on the method, nothing in the #Blob heap that says “this was a query.” The query expression has been erased so thoroughly that the IL is byte-for-byte what you would get from writing the method chain by hand.
The one fingerprint: transparent identifiers
There is exactly one case where a query leaves a trace, and it is worth knowing because it is the only lever a decompiler has. A let clause, or a second from whose body still refers to the first range variable, forces the compiler to carry two values forward through the rest of the chain. It does that by packing them into an anonymous type — a transparent identifier. Consider:
from o in orders
let tax = o.Total * 0.08m
where tax > 5m
select new { o.Id, tax };
That lowers to:
orders
.Select(o => new { o, tax = o.Total * 0.08m })
.Where(t => t.tax > 5m)
.Select(t => new { t.o.Id, t.tax });
The new { o, tax = ... } is not something you wrote — the compiler synthesized it to smuggle o and tax together through the where. It emits a real anonymous type, named something like <>f__AnonymousType0<Person, decimal>, and that type is visible in metadata. When Glass sees a chain that threads an anonymous type carrying the previous range variable through successive operators, it has strong evidence that a let or multi-clause query was present — enough to offer the query form back with confidence. A plain from/where/select leaves no such breadcrumb.
How Glass reconstructs it
Glass.NET decompiles stage 3 and reconstructs stage 2: a clean, fluent method chain with the lambdas inlined and the cached-delegate plumbing hidden. That is the faithful default, because the chain is exactly what the assembly contains. For chains that match the precise pattern the compiler emits from a query — the right operators in the right order, with transparent identifiers where a query would have needed them — Glass can re-sugar back to query syntax so the output reads the way the author likely wrote it. Because this is a reconstruction and not a recovery, it stays conservative: it would rather print a correct method chain than invent a query that was never written. You can decompile through the Visual-Studio-native UI, the CLI, or the MCP server when you want an agent to read the chain for you — all free in Glass.NET.
When re-sugaring is the wrong call
The honest limit: the two forms are behaviorally identical, so no decompiler can ever know which you wrote. A hand-authored people.Where(...).Select(...) and a lowered from p in people where ... select ... produce the same IL to the bit. Re-sugaring is therefore always a guess at intent, not a fact recovered from the binary.
It also simply does not apply to most real chains. Query syntax has clauses for where, select, orderby, group, join, and let — and nothing else. There is no query clause for .Take, .Skip, .Distinct, .First, .Any, or .ToList, so any chain that uses them has no query form to return to and stays fluent. And for IQueryable<T> the same syntax binds to Queryable methods that build an expression tree rather than run in-process; the decompiled chain looks identical, but what it does at runtime is a different story, told in the expression tree — a separate mechanism with its own decompilation.
Takeaway
Query syntax is sugar in the strictest sense: it is rewritten to method calls before the compiler binds anything, and only those calls reach the IL. No attribute, no flag, no metadata row survives to say a query was ever written, which is why every decompiler — Glass included — shows you a method chain. The one exception is the transparent-identifier anonymous type that a let or multi-clause query leaves behind, and that is the single piece of evidence worth looking for when you want to know what the original source really looked like.
Try Nebula.NET
Harden your .NET code in minutes — start with the free edition.