public static PropertyDescriptor GetImageListProperty(PropertyDescriptor currentComponent, ref object instance) { if (instance is object[]) //multiple selection is not supported by this class { return(null); } PropertyDescriptor imageListProp = null; object parentInstance = instance; RelatedImageListAttribute relILAttr = currentComponent.Attributes[typeof(RelatedImageListAttribute)] as RelatedImageListAttribute; if (relILAttr != null) { string[] pathInfo = relILAttr.RelatedImageList.Split('.'); for (int i = 0; i < pathInfo.Length; i++) { if (parentInstance == null) { Debug.Fail("A property specified in the path is null or not yet instanciated at this time"); break; } PropertyDescriptor prop = TypeDescriptor.GetProperties(parentInstance)[pathInfo[i]]; if (prop == null) { Debug.Fail("The path specified to the property is wrong"); break; } if (i == pathInfo.Length - 1) { // we're on the last one, look if that's our guy if (typeof(ImageList).IsAssignableFrom(prop.PropertyType)) { instance = parentInstance; imageListProp = prop; break; } } else { parentInstance = prop.GetValue(parentInstance); } } } return(imageListProp); }
public static PropertyDescriptor GetImageListProperty(PropertyDescriptor currentComponent, ref object instance) { if (instance is object[]) { return(null); } PropertyDescriptor descriptor = null; object component = instance; RelatedImageListAttribute attribute = currentComponent.Attributes[typeof(RelatedImageListAttribute)] as RelatedImageListAttribute; if (attribute != null) { string[] strArray = attribute.RelatedImageList.Split(new char[] { '.' }); for (int i = 0; i < strArray.Length; i++) { if (component == null) { return(descriptor); } PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(component)[strArray[i]]; if (descriptor2 == null) { return(descriptor); } if (i == (strArray.Length - 1)) { if (typeof(ImageList).IsAssignableFrom(descriptor2.PropertyType)) { instance = component; return(descriptor2); } } else { component = descriptor2.GetValue(component); } } } return(descriptor); }