Created
March 20, 2017 15:00
-
-
Save Rottweiler/c63022fc6d6c504d8e8917387d0ce546 to your computer and use it in GitHub Desktop.
Call method by name
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.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