From 8b457a0bb6a93c89a1c36619ff9a9c51423165f5 Mon Sep 17 00:00:00 2001 From: Maximilian Date: Mon, 12 Feb 2018 15:18:23 +0100 Subject: [PATCH] Upgraded main aspnet core project to 2.0 --- ...Query.DataTables.AspNetCore.Example.csproj | 86 ++----------------- .../DataTablesModelBinder.cs | 38 +++++++- .../Mvc.JQuery.DataTables.AspNetCore.csproj | 8 +- .../Mvc.JQuery.DataTables.Common.csproj | 8 +- .../Mvc.JQuery.Datatables.Templates.csproj | 8 +- 5 files changed, 53 insertions(+), 95 deletions(-) diff --git a/Mvc.JQuery.DataTables.AspNetCore.Example/Mvc.JQuery.DataTables.AspNetCore.Example.csproj b/Mvc.JQuery.DataTables.AspNetCore.Example/Mvc.JQuery.DataTables.AspNetCore.Example.csproj index 001d716..c2ad9ea 100644 --- a/Mvc.JQuery.DataTables.AspNetCore.Example/Mvc.JQuery.DataTables.AspNetCore.Example.csproj +++ b/Mvc.JQuery.DataTables.AspNetCore.Example/Mvc.JQuery.DataTables.AspNetCore.Example.csproj @@ -1,94 +1,18 @@  - netcoreapp1.0 + netcoreapp2.0 - $(PackageTargetFallback);portable-net45+win8+wp8+wpa81; Mvc.JQuery.DataTables.Example - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + diff --git a/Mvc.JQuery.DataTables.AspNetCore/DataTablesModelBinder.cs b/Mvc.JQuery.DataTables.AspNetCore/DataTablesModelBinder.cs index 7cb2650..8a4ab8b 100644 --- a/Mvc.JQuery.DataTables.AspNetCore/DataTablesModelBinder.cs +++ b/Mvc.JQuery.DataTables.AspNetCore/DataTablesModelBinder.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc.ModelBinding; +using Microsoft.AspNetCore.Mvc.ModelBinding.Internal; using System; using System.Threading.Tasks; @@ -99,9 +100,42 @@ private DataTablesParam BindLegacyModel(IValueProvider valueProvider, int column private static T GetValue(IValueProvider valueProvider, string key) { ValueProviderResult valueResult = valueProvider.GetValue(key); - return (valueResult==null) + return (valueResult == null) ? default(T) - : (T)valueResult.ConvertTo(typeof(T)); + : ConvertTo(valueResult); + } + + /// + /// Attempts to convert the values in to the specified type. + /// + /// The for conversion. + /// The . + /// + /// The converted value, or the default value of if the value could not be converted. + /// + /// + /// Copyright (c) .NET Foundation and Contributors + /// All rights reserved. + /// Licensed under the Apache License, Version 2.0 (the "License"); you may not use + /// this file except in compliance with the License.You may obtain a copy of the license at: + /// http://www.apache.org/licenses/LICENSE-2.0 + /// Unless required by applicable law or agreed to in writing, software distributed + /// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + /// CONDITIONS OF ANY KIND, either express or implied. See the License for the + /// specific language governing permissions and limitations under the License. + /// + private static T ConvertTo(ValueProviderResult result) + { + object valueToConvert = null; + if (result.Values.Count == 1) + { + valueToConvert = result.Values[0]; + } + else if (result.Values.Count > 1) + { + valueToConvert = result.Values.ToArray(); + } + return ModelBindingHelper.ConvertTo(valueToConvert, result.Culture); } } diff --git a/Mvc.JQuery.DataTables.AspNetCore/Mvc.JQuery.DataTables.AspNetCore.csproj b/Mvc.JQuery.DataTables.AspNetCore/Mvc.JQuery.DataTables.AspNetCore.csproj index 5cbede3..f741182 100644 --- a/Mvc.JQuery.DataTables.AspNetCore/Mvc.JQuery.DataTables.AspNetCore.csproj +++ b/Mvc.JQuery.DataTables.AspNetCore/Mvc.JQuery.DataTables.AspNetCore.csproj @@ -1,7 +1,7 @@  - netstandard1.6;net451 + netstandard2.0 Mvc.JQuery.DataTables Mvc.JQuery.DataTables.AspNetCore Mvc.JQuery.DataTables.AspNetCore @@ -16,9 +16,9 @@ https://github.com/mcintyre321/mvc.jquery.datatables/blob/master/License.txt - - - + + + diff --git a/Mvc.JQuery.DataTables.Common/Mvc.JQuery.DataTables.Common.csproj b/Mvc.JQuery.DataTables.Common/Mvc.JQuery.DataTables.Common.csproj index 81bfe7a..4e1cb47 100644 --- a/Mvc.JQuery.DataTables.Common/Mvc.JQuery.DataTables.Common.csproj +++ b/Mvc.JQuery.DataTables.Common/Mvc.JQuery.DataTables.Common.csproj @@ -24,10 +24,10 @@ - - - - + + + + diff --git a/Mvc.JQuery.Datatables.Templates/Mvc.JQuery.Datatables.Templates.csproj b/Mvc.JQuery.Datatables.Templates/Mvc.JQuery.Datatables.Templates.csproj index a8183bc..3bc7a4c 100644 --- a/Mvc.JQuery.Datatables.Templates/Mvc.JQuery.Datatables.Templates.csproj +++ b/Mvc.JQuery.Datatables.Templates/Mvc.JQuery.Datatables.Templates.csproj @@ -12,10 +12,10 @@ - - - - + + + +