Skip to content

Instantly share code, notes, and snippets.

@baba-s
Created March 1, 2014 04:23
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 baba-s/9285119 to your computer and use it in GitHub Desktop.
Save baba-s/9285119 to your computer and use it in GitHub Desktop.
/// <summary>
/// リフレクションを使用して名前で指定されたメソッドを呼び出す拡張メソッドを管理するクラス
/// </summary>
public static class ObjectExtensions2
{
/// <summary>
/// 名前で指定されたメソッドを呼び出します
/// </summary>
public static object Invoke(this object obj, string methodName, params object[] parameters)
{
var method = obj.GetType().GetMethod(
methodName,
BindingFlags.Instance | BindingFlags.Public,
null,
Array.ConvertAll(parameters, c => c.GetType()),
null);
return method.Invoke(obj, parameters);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment