public static bool HasPropertyForSelectedItem(this PropertyInfo propertyInfo, Type viewModelType) { if (!typeof(IEnumerable).IsAssignableFrom(propertyInfo.PropertyType)) { throw new ArgumentException("property must be an IEnumerable to get the SelectedItem property"); } return (viewModelType.GetInstanceProperties() .Any(pi => SelectedItemPropertyFilter.GetPossiblePropertyNames(propertyInfo).Contains(pi.Name))); }
public static PropertyInfo GetPropertyForSelectedItem(this PropertyInfo propertyInfo, Type viewModelType) { if (!typeof(IEnumerable).IsAssignableFrom(propertyInfo.PropertyType)) { throw new ArgumentException("property must be an IEnumerable to get the SelectedItem property"); } var collectionItemType = propertyInfo.PropertyType.GetCollectionItemType(); return (viewModelType.GetInstanceProperties() .SingleOrDefault( pi => pi.PropertyType.IsAssignableFrom(collectionItemType) && SelectedItemPropertyFilter.GetPossiblePropertyNames(propertyInfo).Contains(pi.Name))); }