Skip to content

Instantly share code, notes, and snippets.

@ZloyChert
Last active September 21, 2018 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZloyChert/c1b013b35cc3c76c45f2b8b6f39f9196 to your computer and use it in GitHub Desktop.
Save ZloyChert/c1b013b35cc3c76c45f2b8b6f39f9196 to your computer and use it in GitHub Desktop.
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