public class DynamicSample
{
public string Name { get; set;}
public int Add(int a, int b)
{
return a + b;
}
}
DynamicSample dynamicSample = new DynamicSample();
//将"Add"作为参数获得Add方法,获得方法名作为变量名
var addMethod = typeof(DynamicSample).GetMethod("Add");
int re = (int)addMethod.Invoke(dynamicSample, new object[] { 1, 2 });
dynamic dynamicSample2 = new DynamicSample();
int re2 = dynamicSample2.Add(1, 2);