-1

My class has two methods that look like this:

void Update()
void Update(string)

With reflection, I want to call the top one, but when I try this:

            const BindingFlags findFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;

            var methodInfo = script.GetType().GetMethod(methodName, findFlags);

I get a AmbiguousMatchException. How do I call the no arg method?

Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356
  • https://learn.microsoft.com/en-us/dotnet/api/system.type.getmethod?view=netframework-4.8#System_Type_GetMethod_System_String_System_Type___ - see the documentation for the `types` parameter. – mjwills Apr 28 '19 at 04:22

1 Answers1

0

Here's how you do it:

            var methodInfo = script.GetType().GetMethod("Update", findFlags, null, new Type[] { }, null);
Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356