Hi there, I'm curious if it's possible to overwrite the 'Delete' method. Or maybe to define own 'global' methods like Save() and Delete().
Background: I'm supposed to rather flag something as 'deleted' instead of really deleting something. Since it needs a lot of patience to implement a property called 'Deleted' and a method called 'DeleteRestore' on every single entity and it's also hard to maintain if something somewhere changes, I'd thought of implementing the property only on the entities necessary and then check for it's existence in the 'DeleteRestore' method. If it exists, it gets flipped; if not, it calls Delete() on the entity.
Currently I'm using an external method like:
ExternalLibrary.GenericMethods.DeleteRestore(object entity) { Type entityType = entity.GetType(); bool? deleted;
try { PropertyInfo pi = entityType.GetProperty("Deleted"); deleted = ((bool?)pi.GetValue(entity, null)) ?? false); pi.SetValue(entity, !deleted, null);
MethodInfo mi = entityType.GetMethod("Save"); mi.Invoke(entity, new object[0]); } catch { } }
to achieve this. But I don't like it that much. I'd rather like to use a 'global' method, so I can call something like
ticket.DeleteRestore();
instead of
ExternalAssembly.GenericMethods.DeleteRestore(ticket);
|