@@ -137,19 +137,29 @@ static void Fix_LambdaFrame_Constructor(MethodDefinition method)
137137 {
138138 // Goal:
139139 // Rename <>c__DisplayClass0_0 to <*MethodName*>c__AnonStorey* for lambda class name
140- // How:
141- // IL_0000: ldarg.0
142- // >> IL_?: ldstr "<"
143- // >> IL_?: ldarg.0
144- // >> IL_?: callvirt instance string Microsoft.CodeAnalysis.CSharp.Symbol::get_Name()
145- // >> IL_?: ldstr ">c__AnonStorey"
146- // IL_0001: ldarg.2
147- // IL_0002: ldarg.3
148- // IL_0003: ldarg.s closureId
149- // IL_0005: call string Microsoft.CodeAnalysis.CSharp.LambdaFrame::MakeName(class Microsoft.CodeAnalysis.SyntaxNode, valuetype Microsoft.CodeAnalysis.CodeGen.DebugId, valuetype Microsoft.CodeAnalysis.CodeGen.DebugId)
150- // >> IL_?: call string [mscorlib]System.String::Concat(string, string, string, string)
151- // IL_000a: ldarg.1
152- // IL_000b: call instance void Microsoft.CodeAnalysis.CSharp.Symbols.SynthesizedContainer::.ctor(string, class Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol)
140+ //
141+ // How for Roslyn:
142+ // Modify constructor of LambdaFrame from
143+ // LambdaFrame(MethodSymbol topLevelMethod, ...)
144+ // : base(MakeName(...
145+ // To
146+ // LambdaFrame(MethodSymbol topLevelMethod, ...)
147+ // : base("<" + topLevelMethod.Name + ">c__AnonStorey" + MakeName(...
148+ //
149+ // How for IL:
150+ // Insert codes like:
151+ // IL_0000: ldarg.0
152+ // >> IL_?: ldstr "<"
153+ // >> IL_?: ldarg.1
154+ // >> IL_?: callvirt instance string Microsoft.CodeAnalysis.CSharp.Symbol::get_Name()
155+ // >> IL_?: ldstr ">c__AnonStorey"
156+ // IL_0001: ldarg.2
157+ // IL_0002: ldarg.3
158+ // IL_0003: ldarg.s closureId
159+ // IL_0005: call string Microsoft.CodeAnalysis.CSharp.LambdaFrame::MakeName(class Microsoft.CodeAnalysis.SyntaxNode, valuetype Microsoft.CodeAnalysis.CodeGen.DebugId, valuetype Microsoft.CodeAnalysis.CodeGen.DebugId)
160+ // >> IL_?: call string [mscorlib]System.String::Concat(string, string, string, string)
161+ // IL_000a: ldarg.1
162+ // IL_000b: call instance void Microsoft.CodeAnalysis.CSharp.Symbols.SynthesizedContainer::.ctor(string, class Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol)
153163
154164 var il = method . Body . GetILProcessor ( ) ;
155165 var baseInst = il . Body . Instructions [ 1 ] ;
@@ -164,7 +174,7 @@ static void Fix_LambdaFrame_Constructor(MethodDefinition method)
164174 var symbolGetName = method . Module . Import ( symbolGetNameMethod ) ;
165175
166176 il . InsertBefore ( baseInst , il . Create ( OpCodes . Ldstr , "<" ) ) ;
167- il . InsertBefore ( baseInst , il . Create ( OpCodes . Ldarg_0 ) ) ;
177+ il . InsertBefore ( baseInst , il . Create ( OpCodes . Ldarg_1 ) ) ;
168178 il . InsertBefore ( baseInst , il . Create ( OpCodes . Callvirt , symbolGetName ) ) ;
169179 il . InsertBefore ( baseInst , il . Create ( OpCodes . Ldstr , ">c__AnonStorey" ) ) ;
170180
0 commit comments