在.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