I need to have certain attributes of my POCO entities updated on certain actions.
I defined the following Interfaces:
public interface IEntityPOCO
{
Guid Id { get; set; }
}
public interface IHasLastChange : IEntityPOCO
{
DateTime LastChange { get; set; }
}
Here's an example action method:
public void SomeStuff<T>(T entity) where T : class, IEntityPOCO
{
entity.Id = Guid.NewGuid(); // Works like a charm.
if (entity is IHasLastChange)
{
entity.LastChange = DateTime.Now; // Doesn't work. D'oh.
(IHasLastChange)entity.LastChange = DateTime.Now; // Doesn't work either.
}
}
- Since there's quite a lot of different properties (all with corresponding Interfaces) that might be implemented by the POCO, going about the problem with different function signatures is pretty much out of question.
- I'd rather not use reflection for performance reasons.
Is there any feasible way to put me out of my misery?