Call a generic method twice with different types and the compiler does not copy the method. It emits the body once, against placeholders, and records each call's type arguments in a tiny separate structure. A decompiler that does not understand that split will either lose the type arguments or print them where C# would never have written them. Here is the mechanism Glass.NET uses to get it exactly right.
The real question
Consider a method that is generic over one type and the two calls that instantiate it:
using System; static class Program { static T Max<T>(T a, T b) where T : IComparable<T> => a.CompareTo(b) >= 0 ? a : b; static void Main() { int m = Max(3, 7); string s = Max("a", "b"); Console.WriteLine($"{m} {s}"); } } There is one Max in the compiled assembly. Its body is written against a type parameter, not against int or string. So where did the int and the string go, and how does Glass put them back without inventing angle brackets the source never had?
The body is written once, against placeholders
Decompile the method definition and the generic parameter shows up as !!T everywhere a T appeared in source:
.method private hidebysig static !!T Max<([System.Runtime]System.IComparable`1<!!T>) T>(!!T a, !!T b) cil managed { ldarga.s a ldarg.1 constrained. !!T callvirt instance int32 class [System.Runtime]System.IComparable`1<!!T>::CompareTo(!0) ldc.i4.0 blt.s IL_000f ldarg.0 ret IL_000f: ldarg.1 ret } Two index spaces are in play here, and telling them apart is the whole game. !!T (two bangs) is the method's generic parameter. The !0 (one bang) inside IComparable 1<!!T>::CompareTo(!0)is the **type's** generic parameter — the single parameter ofIComparable<>` itself. The CLI keeps method and type parameters in separate numbering namespaces precisely so a generic method on a generic type never has to disambiguate index 0 against index 0.
Note also the constrained. !!T prefix: because T can be a value type, the compiler cannot know at compile time whether CompareTo needs a boxed callvirt. The prefix defers that decision to the JIT, which calls the struct's method directly with no allocation. That is a direct consequence of where T : IComparable<T>, and Glass renders the constraint back into the method signature rather than dropping it.
The type arguments live in a MethodSpec
The body never mentions int. So the call site must carry the instantiation. Decompile Main and each call is a single instruction against a MethodSpec token:
llvm
ldc.i4.3
ldc.i4.7
call !!0 Program::Max<int32>(!!0, !!0)
...
ldstr "a"
ldstr "b"
call !!0 Program::Max<string>(!!0, !!0)
Both instructions point at the same generic method definition, but through two different MethodSpec rows (metadata table 0x2B). Each row has two columns: Method, a reference to the generic Max, and Instantiation, a blob index. The blob is a GENERICINST signature: a one-byte calling-convention marker 0x0A, an argument count, then one encoded type per argument.
For Max<int32> the blob bytes are 0A 01 08: calling convention GENERICINST (0x0A), one argument (0x01), and ELEMENT_TYPE_I4 (0x08). For Max<string> the final byte is 0x0E (ELEMENT_TYPE_STRING). Three bytes are the entire difference between the two calls. Everything else — the body, the parameter list, the return — is shared.
Substitute, then decide on the brackets
Glass walks this in two moves. First it resolves the MethodSpec: follow Method to the open generic Max<T>, read Instantiation to get the ordered type arguments [Int32], and bind !!0 to Int32. That alone is enough to print a correct, if verbose, Max<int>(3, 7).
The second move is what makes the output read like source. C# lets you omit type arguments when the compiler can infer them from the ordinary arguments. Here both parameters are of type T and both arguments are int, so inference recovers T = int on its own — which is why the source wrote Max(3, 7), not Max<int>(3, 7). Glass reproduces that: after substitution it asks whether re-running inference over the un-annotated call would land on the same closed method. When it would, the angle brackets are dropped.
When inference cannot recover the arguments, Glass keeps them. The classic case is a type argument that appears only in the return position:
`csharp
static T Create() where T : new() => new T();
var list = Create>(); // no argument to infer from
`
Create has no parameters, so nothing at the call site constrains T. The IL carries Create<class List1> in its MethodSpec, and Glass must emit Create>()` verbatim — dropping the brackets would produce code that does not compile.
When the heuristic has to be conservative
Inference recovery is a judgment call, and Glass errs toward correctness over brevity. If a method is overloaded such that removing the type arguments would make a different overload win — or make the call ambiguous — Glass keeps the explicit arguments even though the original source might have relied on inference. The decompiled code is then slightly more verbose than the source but provably compiles to the same MethodSpec. That trade is deliberate: a decompiler that produces shorter code which binds to the wrong method is worse than useless.
The other honest limit: the type-argument names are gone. A blob encodes System.Int32, never the fact that the author's inferred T was spelled TKey at some other definition. Names of generic parameters on definitions survive in metadata; the types bound to them at a call site are structural, so Glass prints the real type, int, which is what the runtime sees anyway.
Takeaway
A generic call in .NET is a join: a shared body against placeholders, plus a per-call-site MethodSpec whose blob carries the real types. Read the blob, bind !!0 through !!n, keep method and type parameters in their separate index spaces, then let inference decide the brackets — and the decompiled call reads exactly like the C# that produced it. Glass.NET does this on every generic call site, which is why the output is readable instead of a wall of angle brackets. See the IL and metadata view to inspect the MethodSpec rows yourself.
