@@ -1362,6 +1362,44 @@ private bool SkipExpressionBreakpointsSequences(MethodDefinition methodDefinitio
1362
1362
return false ;
1363
1363
}
1364
1364
1365
+ public bool SkipInlineAssignedAutoProperty ( bool skipAutoProps , MethodDefinition methodDefinition , Instruction instruction )
1366
+ {
1367
+ if ( ! skipAutoProps ) return false ;
1368
+
1369
+ return SkipGeneratedBackingFieldAssignment ( methodDefinition , instruction ) ;
1370
+ }
1371
+
1372
+ private static bool SkipGeneratedBackingFieldAssignment ( MethodDefinition methodDefinition , Instruction instruction )
1373
+ {
1374
+ /*
1375
+ For inline initialization of properties the compiler generates a field that is set in the constructor of the class.
1376
+ To skip this we search for compiler generated fields that are set in the constructor.
1377
+
1378
+ .field private string '<SurName>k__BackingField'
1379
+ .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
1380
+ 01 00 00 00
1381
+ )
1382
+
1383
+ .method public hidebysig specialname rtspecialname
1384
+ instance void .ctor () cil managed
1385
+ {
1386
+ IL_0000: ldarg.0
1387
+ IL_0001: ldsfld string[System.Runtime] System.String::Empty
1388
+ IL_0006: stfld string TestRepro.ClassWithPropertyInit::'<SurName>k__BackingField'
1389
+ ...
1390
+ }
1391
+ ...
1392
+ */
1393
+ IEnumerable < FieldDefinition > autogeneratedBackingFields = methodDefinition . DeclaringType . Fields . Where ( x =>
1394
+ x . CustomAttributes . Any ( ca => ca . AttributeType . FullName . Equals ( typeof ( CompilerGeneratedAttribute ) . FullName ) ) &&
1395
+ x . FullName . EndsWith ( "k__BackingField" ) ) ;
1396
+
1397
+ return instruction . OpCode == OpCodes . Ldarg &&
1398
+ instruction . Next ? . Next ? . OpCode == OpCodes . Stfld &&
1399
+ instruction . Next ? . Next ? . Operand is FieldReference fr &&
1400
+ autogeneratedBackingFields . Select ( x => x . FullName ) . Contains ( fr . FullName ) ;
1401
+ }
1402
+
1365
1403
private static bool SkipBranchGeneratedExceptionFilter ( Instruction branchInstruction , MethodDefinition methodDefinition )
1366
1404
{
1367
1405
if ( ! methodDefinition . Body . HasExceptionHandlers )
0 commit comments