Skip to content

Commit 4bbf812

Browse files
Garvin CasimirGarvin Casimir
authored andcommitted
Removing _properties array and commenting invidual property search till it can be fixed.
1 parent 0328aaa commit 4bbf812

File tree

1 file changed

+38
-39
lines changed

1 file changed

+38
-39
lines changed

DatatablesParser/DatatablesParser.cs

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,14 @@ public DataTablesParser(HttpRequestBase httpRequest, IQueryable<T> queriable)
7272
_queriable = queriable;
7373
_httpRequest = httpRequest;
7474
_type = typeof(T);
75-
_properties = _type.GetProperties();
7675

7776
//user regex instead of throwing exception or using tryparse
7877
var integerTest = new Regex(@"^\d+$");
7978

8079
//Is this readable? Well if you can read all this expression stuff then this is nothing~!
8180
//This associates class properties with relevant datatable configuration options
8281
_propertyMap = (from key in _httpRequest.Params.AllKeys.Where(k => k.StartsWith(INDIVIDUAL_DATA_KEY_PREFIX))
83-
join prop in _properties on _httpRequest[key] equals prop.Name
82+
join prop in _type.GetProperties() on _httpRequest[key] equals prop.Name
8483
let extractIndex = key.Replace(INDIVIDUAL_DATA_KEY_PREFIX, string.Empty).Trim()
8584
let searchable = _httpRequest[INDIVIDUAL_SEARCHABLE_KEY_PREFIX + extractIndex] == null ? true : _httpRequest[INDIVIDUAL_SEARCHABLE_KEY_PREFIX + extractIndex].Trim() == "true"
8685
let sortable = _httpRequest[INDIVIDUAL_SORTABLE_KEY_PREFIX + extractIndex] == null ? true : _httpRequest[INDIVIDUAL_SORTABLE_KEY_PREFIX + extractIndex].Trim() == "true"
@@ -250,8 +249,8 @@ private void ApplySort()
250249
//Not sure if we care about the queriables that come in sorted? IOrderedQueryable does not seem to be a reliable test
251250
if (!sorted)
252251
{
253-
var firstProp = Expression.Property(paramExpr, _properties[0].Name);
254-
var propType = _properties[0].PropertyType;
252+
var firstProp = Expression.Property(paramExpr, _propertyMap.First().Value.Property);
253+
var propType = _propertyMap.First().Value.Property.PropertyType;
255254
var delegateType = Expression.GetFuncType(typeof(T), propType);
256255
var propertyExpr = Expression.Lambda(delegateType, firstProp, paramExpr);
257256

@@ -271,40 +270,40 @@ private void ApplySort()
271270
/// Compound predicate expression with the individual search predicates that will filter the results
272271
/// per an individual column
273272
/// </summary>
274-
private Expression<Func<T, bool>> IndividualPropertySearch
275-
{
276-
get
277-
{
278-
var paramExpr = Expression.Parameter(typeof(T), "val");
279-
Expression whereExpr = Expression.Constant(true); // default is val => True
280-
281-
foreach (string key in _httpRequest.Params.AllKeys.Where(x => x.StartsWith(INDIVIDUAL_SEARCH_KEY_PREFIX)))
282-
{
283-
// parse the property number
284-
int property = -1;
285-
if (!int.TryParse(_httpRequest[key].Replace(INDIVIDUAL_SEARCH_KEY_PREFIX, string.Empty), out property)
286-
|| property >= _properties.Length || string.IsNullOrEmpty(_httpRequest[key]))
287-
break; // ignore if the option is invalid
288-
289-
string query = _httpRequest[key].ToLower();
290-
291-
// val.{PropertyName}.ToString().ToLower().Contains({query})
292-
var toStringCall = Expression.Call(
293-
Expression.Call(
294-
Expression.Property(paramExpr, _properties[property]), "ToString", new Type[0]),
295-
typeof(string).GetMethod("ToLower", new Type[0]));
296-
297-
// reset where expression to also require the current contraint
298-
whereExpr = Expression.And(whereExpr,
299-
Expression.Call(toStringCall,
300-
typeof(string).GetMethod("Contains"),
301-
Expression.Constant(query)));
302-
303-
}
304-
305-
return Expression.Lambda<Func<T, bool>>(whereExpr, paramExpr);
306-
}
307-
}
273+
//private Expression<Func<T, bool>> IndividualPropertySearch
274+
//{
275+
// get
276+
// {
277+
// var paramExpr = Expression.Parameter(typeof(T), "val");
278+
// Expression whereExpr = Expression.Constant(true); // default is val => True
279+
280+
// foreach (string key in _httpRequest.Params.AllKeys.Where(x => x.StartsWith(INDIVIDUAL_SEARCH_KEY_PREFIX)))
281+
// {
282+
// // parse the property number
283+
// int property = -1;
284+
// if (!int.TryParse(_httpRequest[key].Replace(INDIVIDUAL_SEARCH_KEY_PREFIX, string.Empty), out property)
285+
// || property >= _properties.Length || string.IsNullOrEmpty(_httpRequest[key]))
286+
// break; // ignore if the option is invalid
287+
288+
// string query = _httpRequest[key].ToLower();
289+
290+
// // val.{PropertyName}.ToString().ToLower().Contains({query})
291+
// var toStringCall = Expression.Call(
292+
// Expression.Call(
293+
// Expression.Property(paramExpr, _properties[property]), "ToString", new Type[0]),
294+
// typeof(string).GetMethod("ToLower", new Type[0]));
295+
296+
// // reset where expression to also require the current contraint
297+
// whereExpr = Expression.And(whereExpr,
298+
// Expression.Call(toStringCall,
299+
// typeof(string).GetMethod("Contains"),
300+
// Expression.Constant(query)));
301+
302+
// }
303+
304+
// return Expression.Lambda<Func<T, bool>>(whereExpr, paramExpr);
305+
// }
306+
//}
308307

309308
/// <summary>
310309
/// Expression for an all column search, which will filter the result based on this criterion
@@ -316,7 +315,7 @@ private Expression<Func<T, bool>> ApplyGenericSearch
316315
string search = _httpRequest["sSearch"];
317316

318317
// default value
319-
if (string.IsNullOrWhiteSpace(search) || _properties.Length == 0)
318+
if (string.IsNullOrWhiteSpace(search))
320319
return x => true;
321320

322321
// invariant expressions

0 commit comments

Comments
 (0)