我创建了一个自定义词典来实现就可以了IDataErrorInfo
接口属性,但是当我尝试将值设置到这个字典的一个实例:自定义词典只读
自定义词典:
public class MyDictionary<TKey, TValue> : Dictionary<TKey, TValue>, IDataErrorInfo
{
public string Error
{
get { throw new NotImplementedException(); }
}
public string this[string columnName]
{
get { throw new NotImplementedException(); }
}
}
然后:
MyDictionary<string, string> myDict = new MyDictionary<string, string>();
Dictionary["key"] = "value";
我得到以下错误:
Property or indexer 'MyDictionary.this[string]' cannot be assigned to -- it is read only
我想我错过了某种Getter/Setter。但不应该从基类Dictionary继承吗?我如何创建它?
一个[MCVE]将是有益的,但 –