What is BindingFlags.InvokeMethod?

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!");
}
+3
source share
2 answers

InvokeMethodnot used GetMethod, but used when you pass BindingFlagsin Type.InvokeMember.

BindingFlags - , ( MSDN, "", "" '' '). , BindingFlags.

+4

MSDN InvokeMethod:

, . .

InvokeMember.

+2

Source: https://habr.com/ru/post/1759362/


All Articles