Write result = data.Parse(text, strict: true); where data is dynamic, and the C# compiler does not emit a call. It emits a small program: a static field to hold a call site, a null check that builds the site the first time through, a factory call that describes the operation in metadata, an array that describes each argument, and finally an invoke through a delegate stored on the site. A decompiler that stops at transliterating IL hands you all of that and lets you reverse-engineer your own source. The interesting work is recognizing that the whole apparatus stands for one expression — and reading the binder closely enough to recover not just data.Parse(...) but the strict: label on the second argument.
The real question
dynamic is erased. In metadata it is literally System.Object; there is no runtime type called "dynamic." So every operation that would normally bind at compile time — a method call, an operator, a cast, an index — has to be deferred to runtime instead, resolved against whatever type actually shows up. The mechanism .NET uses for that is the DLR call site: a CallSite<T> whose Target delegate is rebuilt lazily by a CallSiteBinder. The question for a decompiler is not "what does this IL do" — it plainly reads and writes a cached field and invokes a delegate. The question is "which single C# expression did the compiler start from," and the answer is written entirely in which binder was built and how.
What the compiler emits
Take one dynamic member invocation:
public static class Demo { public static object Run(dynamic data, string text) => data.Parse(text, strict: true); } The compiler generates a private nested class — call it the site cache — named <>o__0, holding one static CallSite<T> field per dynamic operation in the method. Here there is one, <>p__0, whose generic argument is the delegate signature the operation will use. The method body then follows a fixed null-check-then-create shape:
.class nested private abstract sealed auto ansi '<>o__0' { .field public static class [System.Core]System.Runtime.CompilerServices.CallSite`1 <class [System.Core]...Func`5<class ...CallSite, object, string, bool, object>> '<>p__0' } .method public hidebysig static object Run(object data, string text) cil managed { ldsfld class ...CallSite`1<...Func`5<...>> Demo/'<>o__0'::'<>p__0' brtrue.s IL_0040 ldc.i4.0 ldstr "Parse" ldnull ldtoken Demo call class [System.Core]...Type ...Type::GetTypeFromHandle(valuetype ...RuntimeTypeHandle) ldc.i4.3 newarr [Microsoft.CSharp]...CSharpArgumentInfo // ... three CSharpArgumentInfo.Create(...) entries stored into the array ... call class ...CallSiteBinder [Microsoft.CSharp]Microsoft.CSharp.RuntimeBinder.Binder:: InvokeMember(valuetype ...CSharpBinderFlags, string, class ...IEnumerable`1<...Type>, class ...Type, class ...IEnumerable`1<...CSharpArgumentInfo>) call class ...CallSite`1<...>!0 ...CallSite`1<...>::Create(class ...CallSiteBinder) stsfld class ...CallSite`1<...> Demo/'<>o__0'::'<>p__0' IL_0040: ldsfld class ...CallSite`1<...> Demo/'<>o__0'::'<>p__0' ldfld !0 class ...CallSite`1<...Func`5<...>>::Target ldsfld class ...CallSite`1<...> Demo/'<>o__0'::'<>p__0' ldarg.0 ldarg.1 ldc.i4.1 callvirt instance object ...Func`5<...CallSite, object, string, bool, object>::Invoke(...) ret } Read the shape, because it is the entire signature of a dynamic site. ldsfld loads the cached site; brtrue.s jumps straight to the invoke if it already exists. The cold path builds a CallSiteBinder with Binder.InvokeMember, wraps it with CallSite<T>.Create, and stsflds it back. Both paths land at IL_0040, load the site's Target delegate, push the site itself as the first argument (the DLR convention), push the real arguments — data, text, and the literal true for the strict parameter — and callvirt Invoke. The delegate type Func<CallSite, object, string, bool, object> tells you the arity precisely: site plus three operands returning object.
The binder is the source
Everything the decompiler needs to rebuild the line is in the two arguments it cannot see from the delegate alone: the CSharpBinderFlags passed to the factory, and the CSharpArgumentInfo array. The factory name fixes the operation category. Binder.InvokeMember is a member call; the "Parse" string literal (the ldstr above) is the member name. Binder.BinaryOperation carries a System.Linq.Expressions.ExpressionType — Add, LessThan, Equal — so x + y and x < y are distinguished by that enum, not by any opcode. Binder.Convert carries the target Type, which is how int n = someDynamic; is told apart from a plain assignment. Binder.GetMember/SetMember are property reads and writes, and Binder.GetIndex/SetIndex are indexers. CSharpBinderFlags records context the expression shape hides — CheckedContext for arithmetic compiled inside checked, ResultDiscarded for a statement-level call whose value is thrown away, InvokeSimpleName for Foo() vs this.Foo().
The per-argument detail lives in the CSharpArgumentInfo array, one entry per operand, each built with CSharpArgumentInfo.Create(CSharpArgumentInfoFlags, string name). That second parameter is the key to named arguments: for strict: true the entry carries NamedArgument in its flags and the literal "strict" as its name, so a decompiler that reads the array can put the label back — plain transliteration cannot. The flags encode the rest of how each value was passed: UseCompileTimeType means the operand was pinned to its static type rather than treated as dynamic (the compiler sets this for the typed text and the constant true), IsRef/IsOut mark ref/out passing, and Constant marks a compile-time constant. The receiver data carries None — it is the dynamic target whose runtime type drives resolution.
How Glass folds it back
Glass.NET is a free decompiler built on ICSharpCode.Decompiler, the engine behind ILSpy, and dynamic reconstruction is one of its pattern transforms. It matches the whole call-site shape as a unit — the <>o__N cache class, the brtrue-guarded lazy init, the Binder.* factory call, the CallSite<T>.Create, and the matching .Target(site, ...) invoke whose first argument is the site itself — and treats it as a single logical operation. It then reads the factory to learn the category, reads the member-name ldstr or the ExpressionType or target Type, walks the CSharpArgumentInfo array to learn each operand's role and name, and reconstructs the expression. Open Demo.Run in the decompiled view and you get the line you wrote, label and all:
public static object Run(dynamic data, string text) => data.Parse(text, strict: true); The <>o__0 class and <>p__0 field are suppressed from the tree because every reference to them has been rewritten. One other breadcrumb makes the dynamic keyword itself recoverable: dynamic is object in metadata, so the compiler marks every dynamic position in a signature with System.Runtime.CompilerServices.DynamicAttribute — a plain marker for a bare dynamic, a bool[] transform for nested positions like List<dynamic> or Func<dynamic, int>. Glass reads that attribute and prints dynamic exactly where it belongs, falling back to object where it is absent. The assembly-information view shows the attribute on the members directly.
The edge cases
Three shapes are worth knowing because they stress the reconstruction in different ways.
- Dynamic in LINQ. A query like
from x in src where x.IsActive select x.Nameover adynamicelement compiles each dynamic member access (x.IsActive,x.Name) into its ownBinder.GetMembersite, then wraps those in the usualWhere/Selectlambda caches. The decompiler has to fold the call sites inside the lambda bodies before it can recognize the query pattern around them. Glass does the inner dynamic fold first, so the restored lambda readsx => x.IsActive, and only then reassembles the query — otherwise the LINQ recognizer would never match. - Named and optional arguments. As above, each
CSharpArgumentInfocan carry a name. Mixed positional-and-named calls, and calls that skip an optional parameter, are reconstructed purely from the names in the array; drop the array and the labels are gone, which is exactly the information plain IL transliteration loses. - Dynamic indexers.
bag[key]on adynamicis not a method call — it lowers to aBinder.GetIndexsite, andbag[key] = valueto aBinder.SetIndex. Glass maps those back to[]index syntax rather than inventing aget_Item/set_Itemcall, which is what a decompiler that only knewInvokeMemberwould be tempted to show. Compound dynamic assignment (bag[key] += 1) is aGetIndexfeeding aBinaryOperationfeeding aSetIndex, and the whole chain folds to one line.
When it breaks
The reconstruction depends on the lowering being the stock compiler shape. Heavily rewritten or obfuscated assemblies can inline, reorder or share call-site fields across sites in ways that defeat the pattern match; when Glass cannot prove the full shape, it backs off and shows the raw CallSite/Binder/Target machinery rather than guess an expression that might not round-trip. That fallback is honest, not a failure — faithful IL beats a plausible-looking line that never compiled. And the DynamicAttribute breadcrumb only covers positions that appear in a signature; a dynamic used purely as a local never needs the attribute, so Glass infers it from the presence of the call sites themselves. When neither the attribute nor a site is present, an object is just an object.
Takeaway
A single dynamic operation is one of the largest expansions the C# compiler performs: a generated cache class, a static call-site field, a null-checked lazy initializer, a Binder factory call, a CSharpArgumentInfo array and a delegate invoke, all standing in for one expression. The category lives in the factory name, the operator or target type lives in its arguments, and the per-argument detail — ref, constant, static-type pinning, and the named-argument label — lives in the info array. Glass reads all of it back: data.Parse(text, strict: true), x + y, bag[key], the query over dynamic elements, each folded to the line that produced it, with the scaffolding one click away in the IL view when you want to see exactly which binder flags the compiler chose.


