Skip to content

Commit 3cdb83d

Browse files
committed
Merge pull request mcintyre321#36 from AthosXtreme/master
Some code fixes
2 parents 84c07e3 + 2a85722 commit 3cdb83d

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

Mvc.JQuery.Datatables/DataTablesResult.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class DataTablesResult<T, TRes> : DataTablesResult<TRes>
5858
Guard<IEnumerable<bool>>(s => s.ToArray()),
5959
Guard<IEnumerable<double>>(s => s.ToArray()),
6060
Guard<IEnumerable<object>>(s => s.Select(o => GetTransformedValue(o.GetType(), o)).ToArray()),
61+
Guard<bool>(s => s),
6162
Guard<object>(o => (o ?? "").ToString())
6263
};
6364

Mvc.JQuery.Datatables/TypeExtensions.cs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,32 @@
44
using System.Linq;
55
using System.Reflection;
66

7-
public static class TypeExtensions
7+
namespace Mvc.JQuery.Datatables
88
{
9-
public static IEnumerable<PropertyInfo> GetSortedProperties(this Type t)
9+
public static class TypeExtensions
1010
{
11-
return from pi in t.GetProperties()
12-
let da = (DisplayAttribute)pi.GetCustomAttributes(typeof(DisplayAttribute), false).SingleOrDefault()
13-
let order = ((da != null && da.Order != 0) ? da.Order : int.MaxValue)
14-
orderby order
15-
select pi;
16-
}
11+
public static IEnumerable<PropertyInfo> GetSortedProperties(this Type t)
12+
{
13+
return from pi in t.GetProperties()
14+
let da = (DisplayAttribute)pi.GetCustomAttributes(typeof(DisplayAttribute), false).SingleOrDefault()
15+
let order = ((da != null && da.GetOrder() != null && da.GetOrder() >= 0) ? da.Order : int.MaxValue)
16+
orderby order
17+
select pi;
18+
}
1719

18-
public static IEnumerable<PropertyInfo> GetSortedProperties<T>()
19-
{
20-
return typeof(T).GetSortedProperties();
21-
}
22-
public static IEnumerable<PropertyInfo> GetProperties(this Type t)
23-
{
24-
return from pi in t.GetProperties()
25-
select pi;
26-
}
20+
public static IEnumerable<PropertyInfo> GetSortedProperties<T>()
21+
{
22+
return typeof(T).GetSortedProperties();
23+
}
24+
public static IEnumerable<PropertyInfo> GetProperties(this Type t)
25+
{
26+
return from pi in t.GetProperties()
27+
select pi;
28+
}
2729

28-
public static IEnumerable<PropertyInfo> GetProperties<T>()
29-
{
30-
return typeof(T).GetSortedProperties();
30+
public static IEnumerable<PropertyInfo> GetProperties<T>()
31+
{
32+
return typeof(T).GetSortedProperties();
33+
}
3134
}
3235
}

Mvc.JQuery.Datatables/TypeFilters.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,12 @@ public static string StringFilter(string q, string columnname, Type columntype,
8181
{
8282
if (q.StartsWith("^"))
8383
{
84-
return columnname + ".ToLower().StartsWith(\"" + q.ToLower().Replace("\"", "\"\"") + "\")";
84+
return "(!string.IsNullOrEmpty(" + columnname + ") && " + columnname + ".ToLower().StartsWith(\"" + q.ToLower().Replace("\"", "\"\"") + "\"))";
8585
}
8686
else
8787
{
88-
return columnname + ".ToLower().Contains(\"" + q.ToLower().Replace("\"", "\"\"") + "\")";
88+
return "(!string.IsNullOrEmpty(" + columnname + ") && " + columnname + ".ToLower().Contains(\"" + q.ToLower().Replace("\"", "\"\"") + "\"))";
8989
}
9090
}
91-
9291
}
9392
}

0 commit comments

Comments
 (0)