-
-
Save ZloyChert/c1b013b35cc3c76c45f2b8b6f39f9196 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
[StructLayout(LayoutKind.Explicit)] | |
public class CustomStructWithLayout | |
{ | |
[FieldOffset(0)] | |
public Test1 Test1; | |
[FieldOffset(0)] | |
public Test2 Test2; | |
} | |
public class Test1 | |
{ | |
public virtual int Useless(int param) | |
{ | |
Console.WriteLine(param); | |
return param; | |
} | |
} | |
public class Test2 | |
{ | |
public virtual int Useless() | |
{ | |
return 888; | |
} | |
} | |
public class Stub | |
{ | |
public void Foo(int stub) { } | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Test2 fake = new CustomStructWithLayout | |
{ | |
Test2 = new Test2(), | |
Test1 = new Test1() | |
}.Test2; | |
Stub bar = new Stub(); | |
int param = 55555; | |
bar.Foo(param); | |
fake.Useless(); | |
Console.Read(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment