Pass concrete object type as parameter for generic method
I suspect you want something like this:
public static Boolean PurgeDataObject(this IDataObject dataObject, Guid uid)
{
return PurgeDataObjectImpl((dynamic) dataObject, uid);
}
private static Boolean PurgeDataObjectImpl<T>(T dataObject, Guid uid)
where T : IDataObject
{
return DataProvider.DeleteDataObject<T>(uid, DataProvider.GetConnection());
}
That uses dataObject
dynamically, getting the "execution-time compiler" to perform type inference to work out T
.
You could just use reflection to do this yourself, using MethodInfo.MakeGenericMethod
- but this way is certainly less code.