在.NET 2.0(与C#3.0),我怎么能创建一个属性访问器通过反射获得委托,当我不知道它的类型在编译时?当财产类型未知时,通过反射获得属性的代理创建委托
例如如果我有int
类型的财产,我可以这样做:
Func<int> getter = (Func<int>)Delegate.CreateDelegate(
typeof(Func<int>),
this, property.GetGetMethod(true));
Action<int> setter = (Action<int>)Delegate.CreateDelegate(
typeof(Action<int>),
this, property.GetSetMethod(true));
,但如果我不知道物业是在编译时什么类型的,我不知道该怎么做。
不知道,但这下面的问题看起来有关:http://stackoverflow.com/questions/773099/generating-delegate-types-dynamically-in-c – Till
'功能'是.NET 3.5 ....是这是一个自定义的'Func '? –
@Marc Gravell - Whoops实际上是在一个针对错误平台的临时项目中玩耍,但它可以在.NET 2.0中使用自定义的Func。 –
Ergwun