我已经定义了一个局部类,像这样的属性:
public partial class Item{
public string this[string key]
{
get
{
if (Fields == null) return null;
if (!Fields.ContainsKey(key))
{
var prop = GetType().GetProperty(key);
if (prop == null) return null;
return prop.GetValue(this, null) as string;
}
object value = Fields[key];
return value as string;
}
set
{
var property = GetType().GetProperty(key);
if (property == null)
{
Fields[key] = value;
}
else
{
property.SetValue(this, value, null);
}
}
}
}
这样我可以这样做:
myItem["key"];
并获得字段字典的内容。 但是,当我建立我得到:
“成员名称不能与它们的封闭类型”
为什么?