Decompiles a `u8` string literal backed by static data as a `new byte[]` expression.
Input code
For example, given:
C#: if (bytes.StartsWith("PK\x03\x04"u8) || bytes.StartsWith("PK\x05\x06"u8) || bytes.StartsWith("PK\x07\x08"u8)) { return "application/zip"; }
IL:
ldarg.0
ldsflda valuetype ''/'__StaticArrayInitTypeSize=5'
''::AB26C88D690490A5B3D849CB2940BC0D41C0581931FCC7642193E2389A85BCF5
ldc.i4.4
newobj instance void valuetype [System.Runtime]System.ReadOnlySpan1<uint8>::.ctor(void*, int32) call bool [System.Memory]System.MemoryExtensions::StartsWith<uint8>( valuetype [System.Runtime]System.ReadOnlySpan1<!!0>,
valuetype [System.Runtime]System.ReadOnlySpan`1<!!0>)
Erroneous output
if (bytes.StartsWith(new byte[4] { 80, 75, 3, 4 }) || bytes.StartsWith(new byte[4] { 80, 75, 5, 6 }) || bytes.StartsWith(new byte[4] { 80, 75, 7, 8 })) { return "application/zip"; }
There is no newarr in the IL.
The decompiled C# is content-equivalent, but it is not equivalent in its storage/allocation semantics. If the decompiled code is recompiled, the new byte[4] expressions will introduce array allocations that do not exist in the original code.
Details
- Product in use: ILSpy
- Version in use: 11.1.0.9782+a6909b2e1062d2404a52711926fa74030bd96119
Source: icsharpcode/ILSpy