我有以下课程和工厂(省略了不必要的代码)。我有 3 个独立的 IManageableEntryDao 实现,以及在 createDao 方法中访问的字符串/类型映射。
我收到以下编译错误:“ManageableEntry.IManageableEntryDao' 需要 '1' 类型参数”。解决这个问题的最佳实践是什么?我想以某种方式确定是什么吗?还是有替代解决方案?
public interface IManageableEntryDao<T> where T : IManageableEntry {
T findById(long id);
T findByName(string name);
int findUnapprovedCount();
List<T> findUnapproved(ManageableEntryCriteria criteria);
long insert(T manageableEntry);
bool update(T manageableEntry);
bool delete(T manageableEntry);
}
public class ManageableEntryDaoFactory {
public IManageableEntryDao createDao(string manageableEntryType) {
manageableEntryType = manageableEntryType.ToLower();
Type type = daoTypes[manageableEntryType];
if (type != null) {
object dao = Activator.CreateInstance(type);
return dao as IManageableEntryDao;
}
throw new NotImplementedException("Failed to find DAO for type: " + manageableEntryType);
}
}