0

我正在尝试做类似的事情:

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>>

4

0 回答 0