Skip to content

Commit 3a0d836

Browse files
committed
multi targhet
1 parent d590c35 commit 3a0d836

File tree

9 files changed

+45
-27
lines changed

9 files changed

+45
-27
lines changed

Mvc.JQuery.DataTables.Common/DataTableConfigVm.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Mvc.JQuery.DataTables.Serialization;
66
using Newtonsoft.Json;
77
using Newtonsoft.Json.Linq;
8+
using System.Reflection;
89

910
namespace Mvc.JQuery.DataTables
1011
{
@@ -163,7 +164,7 @@ public TTarget Select(params string[] options)
163164
{
164165
_colDef.Filter.type = "select";
165166
_colDef.Filter.values = options.Cast<object>().ToArray();
166-
if (_colDef.Type.IsEnum)
167+
if (_colDef.Type.GetTypeInfo().IsEnum)
167168
{
168169
_colDef.Filter.values = _colDef.Type.EnumValLabPairs();
169170
}
@@ -191,7 +192,7 @@ public TTarget CheckBoxes(params string[] options)
191192
{
192193
_colDef.Filter.type = "checkbox";
193194
_colDef.Filter.values = options.Cast<object>().ToArray();
194-
if (_colDef.Type.IsEnum)
195+
if (_colDef.Type.GetTypeInfo().IsEnum)
195196
{
196197
_colDef.Filter.values = _colDef.Type.EnumValLabPairs();
197198
}

Mvc.JQuery.DataTables.Common/DataTablesFiltering.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Linq;
44
using Mvc.JQuery.DataTables.Reflection;
55
using System.Linq.Dynamic.Core;
6+
using System.Reflection;
7+
68
namespace Mvc.JQuery.DataTables
79
{
810
internal class DataTablesFiltering
@@ -139,7 +141,7 @@ public static bool IsNumericType(DataTablesPropertyInfo propertyInfo)
139141

140142
private static bool IsNumericType(Type type)
141143
{
142-
if (type == null || type.IsEnum)
144+
if (type == null || type.GetTypeInfo().IsEnum)
143145
{
144146
return false;
145147
}
@@ -159,7 +161,7 @@ private static bool IsNumericType(Type type)
159161
case TypeCode.UInt64:
160162
return true;
161163
case TypeCode.Object:
162-
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof (Nullable<>))
164+
if (type.GetTypeInfo().IsGenericType && type.GetGenericTypeDefinition() == typeof (Nullable<>))
163165
{
164166
return IsNumericType(Nullable.GetUnderlyingType(type));
165167
}
@@ -170,7 +172,7 @@ private static bool IsNumericType(Type type)
170172

171173
public static bool IsEnumType(DataTablesPropertyInfo propertyInfo)
172174
{
173-
return propertyInfo.Type.IsEnum;
175+
return propertyInfo.Type.GetTypeInfo().IsEnum;
174176
}
175177

176178
public static bool IsBoolType(DataTablesPropertyInfo propertyInfo)

Mvc.JQuery.DataTables.Common/FilterDef.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Linq;
5+
using System.Reflection;
56

67
namespace Mvc.JQuery.DataTables
78
{
@@ -39,7 +40,7 @@ private void SetDefaultValuesAccordingToColumnType(Type t)
3940
type = "select";
4041
values = new object[] {"True", "False", "null"};
4142
}
42-
else if (t.IsEnum)
43+
else if (t.GetTypeInfo().IsEnum)
4344
{
4445
type = "checkbox";
4546
//values = Enum.GetNames(t).Cast<object>().ToArray();
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net451</TargetFramework>
4+
<TargetFrameworks>netstandard1.6;net451</TargetFrameworks>
55
<RootNamespace>Mvc.JQuery.DataTables</RootNamespace>
6+
<AssemblyName>Mvc.JQuery.DataTables.Common</AssemblyName>
7+
<PackageId>Mvc.JQuery.DataTables.Common</PackageId>
68
</PropertyGroup>
79

810
<ItemGroup>
911
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
1012
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.6.10" />
1113
</ItemGroup>
12-
1314
<ItemGroup>
14-
<Reference Include="Microsoft.CSharp" />
15-
<Reference Include="Newtonsoft.Json">
16-
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
17-
</Reference>
15+
<EmbeddedResource Include="Views\**\*;Content\**\*;Scripts\**\*" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
16+
</ItemGroup>
17+
18+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' ">
19+
<PackageReference Include="System.ComponentModel.Annotations" Version="4.1.0" />
20+
<PackageReference Include="System.ComponentModel.Primitives" Version="4.1.0" />
21+
<PackageReference Include="System.Reflection" Version="4.1.0" />
22+
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.1.0" />
23+
</ItemGroup>
24+
25+
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
1826
<Reference Include="System.ComponentModel.DataAnnotations" />
27+
<Reference Include="System" />
28+
<Reference Include="Microsoft.CSharp" />
29+
<Reference Include="System.Reflection.Introspections" />
30+
1931
</ItemGroup>
2032

2133
</Project>

Mvc.JQuery.DataTables.Common/Processing/StringTransformers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Web;
4+
using System.Reflection;
55

66
namespace Mvc.JQuery.DataTables
77
{
@@ -48,7 +48,7 @@ private static StringTransformer Guard<TVal>(GuardedValueTransformer<TVal> trans
4848
{
4949
return (t, v) =>
5050
{
51-
if (!typeof(TVal).IsAssignableFrom(t))
51+
if (!typeof(TVal).GetTypeInfo().IsAssignableFrom(t))
5252
{
5353
return null;
5454
}

Mvc.JQuery.DataTables.Common/Processing/TypeFilters.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
4+
using System.Reflection;
45
using Mvc.JQuery.DataTables.Reflection;
56

67
namespace Mvc.JQuery.DataTables
78
{
89
static class TypeFilters
910
{
1011
private static readonly Func<string, Type, object> ParseValue =
11-
(input, t) => t.IsEnum ? Enum.Parse(t, input) : Convert.ChangeType(input, t);
12+
(input, t) => t.GetTypeInfo().IsEnum ? Enum.Parse(t, input) : Convert.ChangeType(input, t);
1213

1314
internal static string FilterMethod(string q, List<object> parametersForLinqQuery, Type type)
1415
{
@@ -87,7 +88,7 @@ public static string NumericFilter(string query, string columnname, DataTablesPr
8788

8889
private static object ChangeType(DataTablesPropertyInfo propertyInfo, string query)
8990
{
90-
if (propertyInfo.PropertyInfo.PropertyType.IsGenericType && propertyInfo.Type.GetGenericTypeDefinition() == typeof(Nullable<>))
91+
if (propertyInfo.PropertyInfo.PropertyType.GetTypeInfo().IsGenericType && propertyInfo.Type.GetGenericTypeDefinition() == typeof(Nullable<>))
9192
{
9293
Type u = Nullable.GetUnderlyingType(propertyInfo.Type);
9394
return Convert.ChangeType(query, u);

Mvc.JQuery.DataTables.Common/Reflection/DataTablesTypeInfo.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ public static Func<T, Dictionary<string, object>> ToDictionary(ResponseOptions<T
7575
}
7676
}
7777

78-
public static OrderedDictionary ToOrderedDictionary(T row)
79-
{
80-
var dictionary = new OrderedDictionary();
81-
foreach (var pi in Properties)
82-
{
83-
dictionary[pi.PropertyInfo.Name] = pi.PropertyInfo.GetValue(row, null);
84-
}
85-
return dictionary;
86-
}
78+
//public static OrderedDictionary ToOrderedDictionary(T row)
79+
//{
80+
// var dictionary = new OrderedDictionary();
81+
// foreach (var pi in Properties)
82+
// {
83+
// dictionary[pi.PropertyInfo.Name] = pi.PropertyInfo.GetValue(row, null);
84+
// }
85+
// return dictionary;
86+
//}
8787

8888

8989
}

Mvc.JQuery.DataTables.Common/ResourceHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static string DisplayName(this Enum value)
3737
var enumValue = Enum.GetName(enumType, value);
3838
MemberInfo member = enumType.GetMember(enumValue)[0];
3939

40-
var attrs = member.GetCustomAttributes(typeof(DisplayAttribute), false);
40+
var attrs = member.GetCustomAttributes(typeof(DisplayAttribute), false).ToArray();
4141
var outString = member.Name;
4242
if (attrs.Length > 0)
4343
{

Mvc.JQuery.DataTables.Common/Util/TransformTypeInfo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using Mvc.JQuery.DataTables.Reflection;
4+
using System.Reflection;
45

56
namespace Mvc.JQuery.DataTables.Util
67
{
@@ -15,7 +16,7 @@ public static Dictionary<string, object> MergeTransformValuesIntoDictionary<TInp
1516
var transform = transformInput(tInput);
1617
if (transform != null)
1718
{
18-
foreach (var propertyInfo in transform.GetType().GetProperties())
19+
foreach (var propertyInfo in transform.GetType().GetTypeInfo().GetProperties())
1920
{
2021
dict[propertyInfo.Name] = propertyInfo.GetValue(transform, null);
2122
}

0 commit comments

Comments
 (0)