Skip to content

Instantly share code, notes, and snippets.

@macinnir
Last active December 8, 2015 22:08
Show Gist options
  • Save macinnir/897d03afdffb80cb4e29 to your computer and use it in GitHub Desktop.
Save macinnir/897d03afdffb80cb4e29 to your computer and use it in GitHub Desktop.
Dynamically call method on object in C#
var t = model.GetType();
var mth = t.GetMethod(action);
if (mth != null)
{
try
{
mth.Invoke(model, new object[] { });
}
catch(AmbiguousMatchException)
{
/* ... */
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment