c# - Are there any classes which can supply you with what a MethodInfo/method name would be? -


i wondering if there classes can generate methodbase/methodinfo, or generate method name, without using "magic strings". right i'm doing following:

public void foo(methodinfo method) {     if (string.equals("get_isbar", method.name, stringcomparison.ordinal))     {         // ...     } } 

instead, wondering if there way of getting name, "get_isbar", interface, this:

public interface ibar {     bool isbar { get; } }  public void foo(methodinfo method) {     string barmethodname = getbargettermethodname(typeof(ibar), "isbar");     if (string.equals(barmethodname, method.name, stringcomparison.ordinal))     {         // ...     } } 

i realize there still "magic string" in there, @ least it's more manageable.

use getgetmethod() of propertyinfo:

typeof(ibar).getproperty("isbar").getgetmethod().name 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -