我正在尝试做类似的事情:
public DataObjectBase GetCurrentSettings<T>(string path) where T : DataObjectBase
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentException("Path cannot be empty.");
}
return _currentSettings[T].Invoke(path);
}
但它不会编译。我怎样才能做到这一点?我基本上导入了一个IEnumerable类,可以使用MEF和importmany属性操作我的DataObjects。然后在构造函数中,我将每个操作转换为键控字典,这样我就不必每次调用都运行查询。
_currentSettings是Dictionary<Type, Func<string, DataObject>>