mardi 11 août 2015

Get property ToString with formatting

Using reflection I can do ToString on a property. But is there a way to supply a formatting while doing this?

public static object GetCustomValue(object src, string propName)
{
    return src.GetType().GetMethod(propName).GetValue(src, null);
}

Calling the function like this works fine

GetCustomValue(obj, "ToString")

But I would like to call it with

GetCustomValue(obj, "ToString(\"MMM\")")

Is it possible to add formatting to the ToString when calling the GetMethod in my function?





Aucun commentaire:

Enregistrer un commentaire