0
您好,我想擁有一個複雜類型的可擴展集合,這些集合是其他複雜類型的集合。 我怎麼想這樣做:任何集合中的複雜類型內的複雜類型(屬性網格)
private static void SetExpandableAttrForType(Type type)
{
var props = type.GetProperties();
foreach (var prop in props.Where(x =>!x.PropertyType.IsSimpleType()&& x.CanWrite))
{
SetExpandableAttrForType(prop.PropertyType);
}
TypeDescriptor.AddAttributes(type, new TypeConverterAttribute(typeof (ExpandableObjectConverter)));
}
然後
SetExpandableAttrForType(arrayInstance.GetType().GetElementType());
測試模式:
public class Class1
{
public Class2 Class2Inclass1 { get; set; }
public Class2[] Class2Array { get; set; }
}
public class Class2
{
public Class3 Class3Inclass2 { get; set; }
public string Class2String { get; set; }
public string Class2String2 { get; set; }
}
public class Class3
{
public Class4 Class4Inclass3 { get; set; }
public string Class3String { get; set; }
public int Class3Int { get; set; }
}
public class Class4
{
public int Class4Int { get; set; }
public DateTime Class4Datetime { get; set; }
}