Skip to content

Instantly share code, notes, and snippets.

@Rottweiler
Created March 20, 2017 15:00
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 Rottweiler/c63022fc6d6c504d8e8917387d0ce546 to your computer and use it in GitHub Desktop.
Save Rottweiler/c63022fc6d6c504d8e8917387d0ce546 to your computer and use it in GitHub Desktop.
Call method by name
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
namespace pg1 {
public static class Program {
public static void Main() {
Call(typeof(Program), "Prln", "Hello world"); //calls pg1.Program.Prln
}
public static void Prln(string value) {
Console.WriteLine(value);
}
public static object Call(Type space, string name, params object[] argv) {
List<Type> ptyp = new List<Type>();
foreach(var o in argv) {
ptyp.Add(o.GetType());
}
var m = space.GetMethod(name, ptyp.ToArray());
return m.Invoke(null, argv);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment