public void Test() { TypeAccessor ta = TypeAccessor.GetAccessor(typeof(RootType)); PropertyDescriptorCollection col = ta.CreateExtendedPropertyDescriptors(null, null); PropertyDescriptor prop = col["Type1+Type2+Name"]; RootType obj = new RootType(); object value = prop.GetValue(obj); Assert.AreEqual("test", value); }
public PropertyDescriptorCollection GetItemProperties( PropertyDescriptor[] listAccessors, Type objectViewType, IsNullHandler isNull, bool cache) { PropertyDescriptorCollection pdc = null; if (listAccessors == null || listAccessors.Length == 0) { if (_pdc == null) { _pdc = _typeAccessor != null? _typeAccessor.CreateExtendedPropertyDescriptors(objectViewType, isNull) : new PropertyDescriptorCollection(null); } pdc = _pdc; if (!cache) { _pdc = null; } } else { try { // Lets try to pick out the item type from the list type. // Type itemType = TypeHelper.GetListItemType( listAccessors[listAccessors.Length - 1].PropertyType); if (itemType == typeof(object)) { TypeAccessor parentAccessor = _typeAccessor; foreach (PropertyDescriptor pd in listAccessors) { // We have to create an instance of the list to determine its item type // // Create an instance of the parent. // object parentObject = parentAccessor.CreateInstanceEx(); // Create an instance of the list. // object listObject = pd.GetValue(parentObject); if (listObject == null) { // We failed. Item type can not be determined. // itemType = null; break; } itemType = TypeHelper.GetListItemType(listObject); // Still bad. // if (itemType == typeof(object)) { break; } parentAccessor = TypeAccessor.GetAccessor(itemType); } } if (itemType != null && itemType != typeof(object)) { TypeAccessor ta = TypeAccessor.GetAccessor(itemType); pdc = ta.CreateExtendedPropertyDescriptors(null, isNull); } } catch { } if (pdc == null) { pdc = new PropertyDescriptorCollection(null); } } return(pdc); }