/// <summary> /// Transforms a DataTables sort object into a DapperExtensions sort element. /// </summary> /// <param name="sort"></param> /// <returns></returns> public static ISort GetSortPredicate <TElement>(this Core.IColumn column) { if (column == null) { return(null); } if (column.Sort == null) { return(null); } // Scaffolds type and searches for member (field) name. var typeSearchResult = TypeSearchResult.Scaffold <TElement>(column.Field); // Type does not contains member - returns a null sort to ensure compliance. if (!typeSearchResult.ContainsMember) { return(null); } return(new Sort() { Ascending = column.Sort.Direction == Core.SortDirection.Ascending, PropertyName = column.Field }); }
private static TypeSearchResult[] GetInvalidAttributeTypeSearchResult(Type attr) { TypeSearchResult[] result; if (!InvalidAttributeTypeSearchResults.TryGetValue(attr, out result)) { result = new TypeSearchResult[] { new TypeSearchResult() { MatchedInfo = new TypeSearchInfo() { MatchType = typeof(InvalidAttributeNotificationDrawer <>), Priority = double.MaxValue, Targets = Type.EmptyTypes }, MatchedRule = InvalidAttributeRule, MatchedTargets = Type.EmptyTypes, MatchedType = typeof(InvalidAttributeNotificationDrawer <>).MakeGenericType(attr) } }; InvalidAttributeTypeSearchResults.Add(attr, result); } return(result); }
public SearchResult(TypeSearchResult typeSearchResult, string objectName, string description, Type type, Match match, string link, bool isDescription = false) { this.ObjectName = objectName; this.TypeSearchResult = typeSearchResult; this.Description = description; this.Link = link; this.Type = type; this.MatchType = match.Index == 0 && match.Length == objectName.Length ? MatchType.Total : match.Index == 0 ? MatchType.StartsWith : MatchType.Contains; this.IsDescription = isDescription; }
public SearchResult(TypeSearchResult typeSearchResult, string title, string?description, Match match, string key, string?key2 = null, bool isDescription = false) { this.Title = title; this.TypeSearchResult = typeSearchResult; this.Description = description; this.Key = key; this.Key2 = key2; this.MatchType = match.Index == 0 && match.Length == title.Length ? MatchType.Total : match.Index == 0 ? MatchType.StartsWith : MatchType.Contains; this.IsDescription = isDescription; }
/// <summary> /// Gets the DapperExtensions filter predicate for a given column, if any search is set. /// Important: regex search is not supported. /// </summary> /// <typeparam name="TElement">The type of corresponding entity.</typeparam> /// <param name="column">The column to get search information.</param> /// <param name="forceEqualsOperator">Forces '==' operator for string properties.</param> /// <returns>The field predicate for the specified type or null.</returns> public static IPredicate GetFilterPredicate <TElement>(this Core.IColumn column, bool forceEqualsOperator) where TElement : class { if (column == null) { return(null); } if (!column.IsSearchable) { return(null); } if (column.Search == null) { return(null); } if (column.Search.IsRegex) { return(null); } // Scaffolds type and searches for member (field) name. var typeSearchResult = TypeSearchResult.Scaffold <TElement>(column.Field); // Type does not contains member - returns a null predicate to ensure compliance. if (!typeSearchResult.ContainsMember) { return(null); } // By default, 'LIKE' should be used when searching string content on database. // You can, however, force usage of '==' operator if desired. var _operator = forceEqualsOperator ? Operator.Eq : typeSearchResult.IsStringProperty ? Operator.Like : Operator.Eq; return(new FieldPredicate <TElement>() { PropertyName = column.Field, Operator = _operator, Value = column.Search.Value }); }
public static TypeSearchResult Scaffold <TElement>(string propertyName) { var result = new TypeSearchResult(); result.ContainsMember = false; result.IsStringProperty = false; try { var type = typeof(TElement); var memberInfo = type.GetMember(propertyName).FirstOrDefault(); if (memberInfo != null) { result.ContainsMember = true; Type memberType = null; if (memberInfo is FieldInfo) { var fieldInfo = memberInfo as FieldInfo; memberType = fieldInfo.FieldType; } else if (memberInfo is PropertyInfo) { var propertyInfo = memberInfo as PropertyInfo; memberType = propertyInfo.PropertyType; } if (memberType != null && memberType.IsEquivalentTo(typeof(string))) { result.IsStringProperty = true; } } return(result); } catch { return(result); } }