[英]Class with members created at runtime
我們有一個方法,該方法返回當前在網格中顯示的行。
public override List<object> GetData(int startIndex, int endIndex, string[] rowSortBy, bool[] rowAscSortOrder,
string[] rowGroupByOperations, string rowFilterExpression, ref int rowCount)
{
List<A> list = new List<A>();
.. logic..
return list;
}
問題在於,現在網格列是動態的 ,它們會根據某些條件不斷變化。 這意味着我們不能使用類型化的類,因為數據成員是動態的。 另外,我們無法更改GetData
方法的返回類型,即List<object>
,因為它實際上已由第三方控件使用。
編輯 :我們需要在網格上進行更新。
我能想到的唯一方法就是使用反射來上課。
有任何想法嗎?
聽起來您需要在列表中的對象上實現ICustomTypeDescriptor。
通過這種方式請求屬性,您可以在運行時返回具有新屬性的相關數據。
http://wraithnath.blogspot.co.uk/2011/01/implementing-icustomtypedescriptor-for.html
http://msdn.microsoft.com/zh-CN/magazine/cc163816.aspx
我花了一段時間才弄清楚第一次,因為它有點復雜。 但是它確實有效!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.