I have the following code used to exclude instructions switchto decide which method to call, and only works with the BindingFlags set by me without InvokeMethod. What does it mean InvokeMethodand why it is not needed in the following code:
public enum PublishMethods
{
Method1,
Method2,
Method3
}
private void Form1_Load(object sender, EventArgs e)
{
InvokePublishMethod(PublishMethods.Method2);
}
private void InvokePublishMethod(PublishMethods publishMethod)
{
var publishMethodsType = this.GetType();
var method = publishMethodsType.GetMethod("Publish" + publishMethod, BindingFlags.NonPublic | BindingFlags.Instance);
method.Invoke(this, null);
}
private void PublishMethod2()
{
MessageBox.Show("Method2!");
}
Profk source
share