在.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));
但是如果我在编译时不知道属性的类型,我就不知道该怎么做。
Func<T>
是.NET 3.5中的一个类型....这是一个自定义的Func<T>
吗? - Marc Gravell