Can I set a private property via reflection?
public abstract class Entity
{
private int _id;
private DateTime? _createdOn;
public virtual T Id
{
get { return _id; }
private set { ChangePropertyAndNotify(ref _id, value, x => Id); }
}
public virtual DateTime? CreatedOn
{
get { return _createdOn; }
private set { ChangePropertyAndNotify(ref _createdOn, value, x => CreatedOn); }
}
}
I've tried the following and it does not work, where t represents a type of Entity:
var t = typeof(Entity);
var mi = t.GetMethod("set_CreatedOn", BindingFlags.Instance | BindingFlags.NonPublic);
I guess I can do this but I can't work it out.