0

考虑我有以下代码:

try
{
    using (var scope = CreateDependencies())
    {
        ...
    }
}

当我反编译它时:

try
{
    ILifetimeScope scope;
    int num1;
    if ((uint) (num1 - 1) > 2U)
        scope = Host.CreateDependencies();
    try
    {
        ...
    }
    ...
}
....

如果这完全没有意义,为什么还要额外添加呢?

ILDasm 生成的 ILCode:

.try
{
    IL_00b8:  ldloc.0
    IL_00b9:  ldc.i4.1
    IL_00ba:  sub
    IL_00bb:  ldc.i4.2
    IL_00bc:  ble.un.s   IL_00ca
    IL_00be:  ldarg.0
    IL_00bf:  ldloc.1
    IL_00c0:  call       instance class [Autofac]Autofac.ILifetimeScope MyApp.Host::CreateDependencies()
    IL_00c5:  stfld      class [Autofac]Autofac.ILifetimeScope MyApp.Host/'<RunAsync>d__7'::'<scope>5__2'
    IL_00ca:  nop
    .try
    {
        ...
    }
    ....
}
4

0 回答 0