private bool?GetSelectedMemberPathValue(object item) { if (string.IsNullOrEmpty(SelectedMemberPath)) { return(null); } if (item == null) { return(null); } string[] array = SelectedMemberPath.Split('.'); if (array.Length == 1) { PropertyInfo property = item.GetType().GetProperty(SelectedMemberPath); if (property != null && property.PropertyType == typeof(bool)) { return(property.GetValue(item, null) as bool?); } return(null); } for (int i = 0; i < array.Count(); i++) { Type type = item.GetType(); PropertyInfo property2 = type.GetProperty(array[i]); if (property2 == null) { return(null); } if (i == array.Count() - 1) { if (property2.PropertyType == typeof(bool)) { return(property2.GetValue(item, null) as bool?); } } else { item = property2.GetValue(item, null); } } return(null); }
private void SetSelectedMemberPathValue(object item, bool value) { if (!string.IsNullOrEmpty(SelectedMemberPath) && item != null) { string[] array = SelectedMemberPath.Split('.'); if (array.Length == 1) { PropertyInfo property = item.GetType().GetProperty(SelectedMemberPath); if (property != null && property.PropertyType == typeof(bool)) { property.SetValue(item, value, null); } } else { for (int i = 0; i < array.Count(); i++) { Type type = item.GetType(); PropertyInfo property2 = type.GetProperty(array[i]); if (property2 == null) { break; } if (i == array.Count() - 1) { if (property2.PropertyType == typeof(bool)) { property2.SetValue(item, value, null); } } else { item = property2.GetValue(item, null); } } } } }
private void CheckSelectedPropertyInfo() { object firstItem = null; foreach (var item in ItemsSource) { firstItem = item; break; } if (firstItem == null) { return; } if (SelectedMemberPath.IsNullOrEmpty()) { throw new Exception("Property 'DisplayMemberPath' can not be null or empty."); } if (SelectedMemberPath.IsNullOrEmpty()) { throw new Exception("Property 'SelectedMemberPath' can not be null."); } _selectedPropertyInfo = firstItem.GetType().GetProperty(SelectedMemberPath); _displayPropertyInfo = firstItem.GetType().GetProperty(DisplayMemberPath); if (_displayPropertyInfo == null) { throw new Exception("'" + DisplayMemberPath + "' does not existed."); } if (_selectedPropertyInfo == null || _selectedPropertyInfo.PropertyType != typeof(bool)) { throw new Exception("'" + SelectedMemberPath + "' does not existed , or is not 'bool' type."); } }