private bool MakeNumericFilter(BookDetails o, string option, string condition) { var value = o.GetType().GetRuntimeProperty(option); var exactValue = value.GetValue(o, null); exactValue = Regex.Replace(exactValue.ToString(), @"[^\d]", ""); double res; bool checkNumeric = double.TryParse(exactValue.ToString(), out res); if (checkNumeric) { switch (condition) { case "Equals": try { if (exactValue.ToString() == FilterText) { if (Convert.ToDouble(exactValue) == (Convert.ToDouble(FilterText))) { return(true); } } } catch (Exception e) { Debug.WriteLine(e.Message); } break; case "NotEquals": try { if (Convert.ToDouble(FilterText) != Convert.ToDouble(exactValue)) { return(true); } } catch (Exception e) { Debug.WriteLine(e.Message); return(true); } break; } } return(false); }
private bool MakeStringFilter(BookDetails o, string option, string condition) { var value = o.GetType().GetRuntimeProperty(option); var exactValue = value.GetValue(o, null).ToString(); exactValue = exactValue.ToLower().Split(':')[1]; exactValue = exactValue.Substring(1, exactValue.Length - 1); string text = FilterText.ToLower(); var methods = typeof(string).GetRuntimeMethods(); if (methods.Count() != 0) { if (condition == "Contains") { var methodInfo = methods.FirstOrDefault(method => method.Name == condition); bool result1 = (bool)methodInfo.Invoke(exactValue, new object[] { text }); return(result1); } else if (exactValue.ToString() == text.ToString()) { bool result1 = String.Equals(exactValue.ToString(), text.ToString()); if (condition == "Equals") { return(result1); } else if (condition == "NotEquals") { return(false); } } else if (condition == "NotEquals") { return(true); } return(false); } else { DataSource.RefreshFilter(); return(false); } }