2009-07-28 23 views
4

我有一個基類有很多屬性。包括在這裏是包含元數據的擴展屬性列表。這是包含DisplayName,Description,Name,Type的自定義類的列表&幫助PropertyGrid的值屬性。Converting List <MyClass> Property in PropertyGrid compatible properties in c#

期望的最終結果將是PropertyGrid顯示我的基類屬性與上面列表中的擴展屬性合併。我不希望PropertyGrid將我的列表顯示爲單個條目,而是將每個擴展的屬性與我的基類屬性合併。本質上,PropertyGrid認爲我的擴展屬性列表是對象的第一類屬性。

這可能使用反射或動態類型描述符?

回答

1

它應該是相當簡單的自定義TypeConverter。

像這樣的事情將是一個開始:

public override bool GetPropertiesSupported(ITypeDescriptorContext context) 
{ 
    return true; 
} 

public override PropertyDescriptorCollection GetProperties(
    ITypeDescriptorContext context, object value, Attribute[] attributes) 
{ 
    return base.GetProperties(context, value, attributes). 
    Concat(TypeDescriptor.GetConverter(typeof(TheBaseType)). 
    GetProperties(context, value, attributes)); 
} 
+0

謝謝leppie,你可以把這個的來龍去脈吧。即這是我的ExtendedProperty類或我的基類的自定義類型轉換器? 此外,Concat在PropertyDescriptorCollection的intellisense中沒有出現(targetted framework = 3.5) – dbez 2009-07-28 21:04:59