我有一个IList只读属性的类。我创建了一个简单的扩展方法AddCSV,将多个项目添加到该列表中。我想创建一个动作委托来通过扩展方法填充列表。到目前为止,我有CreateDelegate在扩展方法
private Action<TListPropertyContainer, TDataValue> CreateListPropertySetter<TListPropertyContainer, TDataValue>(string listName)
{
var list = typeof(TListPropertyContainer).GetProperty(listName);
var method = typeof(Extensions).GetMethod("AddCSV");
return (Action<TListPropertyContainer, TDataValue>)Delegate.CreateDelegate(typeof(Action<TListPropertyContainer, TDataValue>), list, method);
}
但显然这是行不通的!
我知道还有其他的选择。例如 一)我可以继承列表到我自己的客户类,并添加AddCSV有 B)我可以做的项目属性读/写,并设置一个完全填充的名单到类
我会很感激,如果有人可以纠正我。
许多THX
西蒙
许多thx。你是对的,我已经过于复杂了!你的代码示例有诀窍。 – 2011-05-13 10:27:26