public static class Extensions {
public static MethodInfo? GetMethodBetter(this Type t, string name)
t.GetMethod(name, BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic) ??
t.GetMethod(name, BindingFlags.Static|BindingFlags.Public|BindingFlags.NonPublic)
public static object? InvokeCoolMethod(this Type t, string name, object obj = null, params object[] parameters) {
var method = GetMethodBetter(t, name);
if (method is null) throw new Exception("method not found");
return method.Invoke(obj, parameters);
public static void Main() {
Console.WriteLine("Hello World");
var program = new Program();
program.SetProperty("a", 123);
program.SetProperty("b", 123.45);
program.SetProperty("cool_shit", "this is neato");
Console.WriteLine("Bye World");
void SetProperty(string name, object value) {
GetType().InvokeCoolMethod($"_SetProperty_{name}", this, value);
void _SetProperty_a(int arg) { Console.WriteLine($"\tset property a with: {arg}"); }
void _SetProperty_b(double arg) { Console.WriteLine($"\tset property b with: {arg}"); }
void _SetProperty_cool_shit(string arg) { Console.WriteLine($"\tset property cool shit with: \"{arg}\""); }