Skip to content

Instantly share code, notes, and snippets.

@ForNeVeR
Last active April 27, 2022 16:16
Show Gist options
  • Save ForNeVeR/def92cbff452c35d3f0241bde3011db8 to your computer and use it in GitHub Desktop.
Save ForNeVeR/def92cbff452c35d3f0241bde3011db8 to your computer and use it in GitHub Desktop.
Declare an object as an instance of System.Math.
using System;
using System.Linq;
using System.Reflection;
class Program
{
class MyClass
{
}
static void Main(string[] args)
{
var mscorlib = AppDomain.CurrentDomain.GetAssemblies().First(a => a.GetType("System.RuntimeType", false, true) != null);
var runtimeType = mscorlib.GetType("System.RuntimeType");
var handle = runtimeType.GetField("m_handle", BindingFlags.Instance | BindingFlags.NonPublic);
var mathTable = handle.GetValue(typeof(Math));
handle.SetValue(typeof(MyClass), mathTable);
var o = new MyClass();
Console.WriteLine(o.GetType()); // System.Math
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment