C# - GetMethod returns null -


i have a class:

public abstract class {  } 

and have b class derives it:

public sealed class b : {     public void somemethod()     {         var method = this.gettype().getmethod("addtext");     }      private void addtext(string text)     {         ...     } } 

why getmethod returning null?

var methodinfo = this.gettype().getmethod("addtext", bindingflags.instance | bindingflags.nonpublic, null, new type[] { typeof(string) }, null); 

your method has parameter, need use overload accepts type array parameter types , binding flags.

in .net method signatures based on name, return type, , parameters.

so if method has parameters have tell reflection parameter types has via type[].


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -