/// <summary> /// Gets text to match with the query from an item. /// Never null. /// </summary> /// <param name="item"/> string TextFromItem(object item) { if (item == null) { return(string.Empty); } var d = new DependencyVariable <string>(); d.SetBinding(item, TextSearch.GetTextPath(this)); return(d.Value ?? string.Empty); }
string TryGetSearch(object item) { string text = string.Empty; var textPath = TextSearch.GetTextPath(this); var propertyInfo = item.GetType().GetProperty(textPath); if (propertyInfo != null) { text = propertyInfo.GetValue(item).ToString(); } return(text); }
// helper method to get display string representation for passed object // uses TextSearch Path if set, // else uses DisplayMemberPath if set, // else uses ToString() private string GetString(object item) { string path = TextSearch.GetTextPath(this); if (string.IsNullOrEmpty(path)) { path = DisplayMemberPath; } if (string.IsNullOrEmpty(path)) { return(item.ToString()); } // use reflection object value = GetPropertyValue(item, path, BindingFlags.Public); if (value != null) { return(value.ToString()); } return(null); }