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
Post a Comment