I want to set the value of LastName to null using reflection.
public void SetPropertyValueToNull(Type t)
{
PropertyInfo prop = t.GetProperty("LastName");
prop.SetValue(t, null, null);
}
I am passing typeof(User) as the parameter from another class where User is a model class which has LastName as one of the properties. It gives me Object does not match target type error.
How can I resolve this issue?
Aucun commentaire:
Enregistrer un commentaire