Skip to content

Commit d71e226

Browse files
committed
Add namespace and fix DisplayAttribute.Order evaluation to avoid exception
when Order is not set.
1 parent 84c07e3 commit d71e226

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

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
}

0 commit comments

Comments
 (0)