Skip to content

Instantly share code, notes, and snippets.

@steviegt6
Created August 29, 2022 04:50
Show Gist options
  • Select an option

  • Save steviegt6/f611c2aa6b8b327367211fcb6ab25fda to your computer and use it in GitHub Desktop.

Select an option

Save steviegt6/f611c2aa6b8b327367211fcb6ab25fda to your computer and use it in GitHub Desktop.
.class private auto ansi '<Module>'
{
}
.class private sequential ansi sealed beforefieldinit MyVoid
extends [System.Runtime]System.Void
{
}
.class public auto ansi beforefieldinit Generic`1<T>
extends [System.Runtime]System.Object
{
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Object::.ctor()
IL_0006: ret
}
}
.class public auto ansi beforefieldinit C
extends [System.Runtime]System.Object
{
.field public class [System.Collections]System.Collections.Generic.List`1<void> Test
.method public hidebysig
instance valuetype MyVoid M (
void a
) cil managed
{
.maxstack 8
IL_0000: newobj instance MyVoid void::.ctor()
IL_0006: ret
}
.method public hidebysig
instance class Generic`1<void> G (
void b
) cil managed
{
.maxstack 8
IL_0000: newobj instance class Generic`1<void> class Generic`1<void>::.ctor()
IL_0006: ret
}
.method public hidebysig
instance void A (
void b
) cil managed
{
.maxstack 8
.locals init (
[0] void
)
ldarg.0
ldfld class [System.Collections]System.Collections.Generic.List`1<void> C::Test
ldloca.s 0
//newobj instance void void::.ctor()
initobj [System.Runtime]System.Void
ldloc.0
callvirt instance void class [System.Collections]System.Collections.Generic.List`1<void>::Add(!0)
IL_0006: ret
}
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
.maxstack 8
IL_0001: ldarg.0
IL_0002: newobj instance void class [System.Collections]System.Collections.Generic.List`1<void>::.ctor()
IL_0003: stfld class [System.Collections]System.Collections.Generic.List`1<void> C::Test
IL_0004: ldarg.0
IL_0005: call instance void [System.Runtime]System.Object::.ctor()
IL_0006: ret
}
}
using System.Collections.Generic;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal sealed class MyVoid : void
{
}
public class Generic<T>
{
}
public class C
{
public List<void> Test = (List<void>)new object();
public MyVoid M(void a)
{
return (MyVoid)new object();
}
public Generic<void> G(void b)
{
return (Generic<void>)new object();
}
public void A(void b)
{
//IL_0014: Expected O, but got Void
List<void> test = Test;
default(void)..ctor();
}
}
{
"version": 1,
"target": "C#",
"mode": "Release",
"branch": "main"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment