views:

30

answers:

0

We have a C# WinForms app with a number of screens that support CRUD operations. We've been trying to create a generic method in the base form class to delete any subsonic ActiveRecord class. This has proved to be a challenge.

calling Delete() for a subsonic type involves calling the static method on the abstract base ActiveRecord<T> class unlike the Save() method that is an instance method:

MySubSoncicClass.Delete(MySubSoncicInstance.Id) vs MySubSonicInstance.Save()

We've been able to create a method using reflection:

private void Delete(SubSonic.IActiveRecord item)
{
Type t = item.GetType().BaseType;
t.InvokeMember("Delete", BindingFlags.InvokeMethod, null, t, new object[] { item.GetPrimaryKeyValue() }); 
}

We'd prefer a generic method like Delete<T>(T item) that could call the Delete() method on the abstract base type ActiveRecord<T> but can't get the syntax correct. Some of our attempts point to ActiveRecord<T> not having a parameterless constructor. Could this be because ActiveRecord<T> is abstract?

Any help would be appreciated.