c # decompile comparison (old)

Foreword

The old ones are the migration of my previous blogs.

We write code sometimes encounter some problems, or we want to optimize our code, we want to see the operation after compilation, then decompilation is a thing that must be done.

text

Here I use reflector and ILSpy, why use these two?

We know that the first kind of reflector is charged, but sometimes we still need to use it under a last resort.

Why do I use it when it is necessary? Because sometimes ILspy cannot be decompiled.

Compared

Because of the different decompilation tools, there are some differences in the compiled things.

The following is the case of the same code decompilation.

reflector

private static void Main(string[] args)
{
    CacheItemPolicy policy = new CacheItemPolicy {
        RemovedCallback = arguments => Console.WriteLine($"缓存被移除的原因:{arguments.RemovedReason}"),
        SlidingExpiration = TimeSpan.FromSeconds(5.0),
        Priority = CacheItemPriority.NotRemovable
    };
    MemoryCache.Default.Add("mykey", "myvalue", policy, null);
    Console.WriteLine(MemoryCache.Default.Get("mykey", null));
    Thread.Sleep(0x1770);
    Console.WriteLine(MemoryCache.Default.Get("mykey", null));
    Console.ReadKey();
}

ILSpy

private static void Main(string[] args)
{
    CacheItemPolicy policy = new CacheItemPolicy {
        RemovedCallback = arguments => Console.WriteLine($"缓存被移除的原因:{arguments.RemovedReason}"),
        SlidingExpiration = TimeSpan.FromSeconds(5.0),
        Priority = CacheItemPriority.NotRemovable
    };
    MemoryCache.Default.Add("mykey", "myvalue", policy, null);
    Console.WriteLine(MemoryCache.Default.Get("mykey", null));
    Thread.Sleep(0x1770);
    Console.WriteLine(MemoryCache.Default.Get("mykey", null));
    Console.ReadKey();
}

Although there are subtle differences, it is still painful to use human brain to see a variety of decompilation, so choose one or two decompilation tools, do not change frequently. It is best to be familiar with the receiver. There is always a reason for charging. If you have money, you can buy a copy for support.
By the way, I would like to remind you that ILSpy is free, go directly to github to download, do not engage in wild, the version may be lower.

Guess you like

Origin www.cnblogs.com/aoximin/p/12728570.html
Old