From 9e3021c4287e75bea7011e7b40951e804424037f Mon Sep 17 00:00:00 2001 From: Victorio Berra Date: Tue, 30 Oct 2018 14:59:16 -0500 Subject: [PATCH 1/2] Add empty list initalizers to help avoid NREs --- DataTables.Queryable/DataTablesAjaxPostModel.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/DataTables.Queryable/DataTablesAjaxPostModel.cs b/DataTables.Queryable/DataTablesAjaxPostModel.cs index c22213f..2e6983a 100644 --- a/DataTables.Queryable/DataTablesAjaxPostModel.cs +++ b/DataTables.Queryable/DataTablesAjaxPostModel.cs @@ -16,6 +16,12 @@ namespace DataTables.Queryable /// public class DataTablesAjaxPostModel { + public DataTablesAjaxPostModel() + { + Columns = new List(); + Order = new List(); + } + /// /// Draw counter. This is used by DataTables to ensure that the Ajax returns from /// server-side processing requests are drawn in sequence by DataTables From f9385d802e2dfa5c9ca018723819dc1b3704943b Mon Sep 17 00:00:00 2001 From: Victorio Berra Date: Tue, 30 Oct 2018 17:27:50 -0500 Subject: [PATCH 2/2] Added a custom exception type to make it easier to handle exceptions when the developer tries to filter on a name that does not exist. --- DataTables.Queryable/DataTables.Queryable.csproj | 1 + DataTables.Queryable/DataTablesRequest.cs | 6 +++--- DataTables.Queryable/NoPropertyByNameException.cs | 9 +++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 DataTables.Queryable/NoPropertyByNameException.cs diff --git a/DataTables.Queryable/DataTables.Queryable.csproj b/DataTables.Queryable/DataTables.Queryable.csproj index f47ca87..d349d44 100644 --- a/DataTables.Queryable/DataTables.Queryable.csproj +++ b/DataTables.Queryable/DataTables.Queryable.csproj @@ -41,6 +41,7 @@ + diff --git a/DataTables.Queryable/DataTablesRequest.cs b/DataTables.Queryable/DataTablesRequest.cs index a64d679..f2e6057 100644 --- a/DataTables.Queryable/DataTablesRequest.cs +++ b/DataTables.Queryable/DataTablesRequest.cs @@ -180,7 +180,7 @@ public DataTablesRequest(NameValueCollection query) } else { - throw new ArgumentException($"Could not find a property called \"{data}\" on type \"{type}\". Make sure you have specified correct value of \"columnDefs.data\" parameter in datatables options."); + throw new NoPropertyByNameException($"Could not find a property called \"{data}\" on type \"{type}\". Make sure you have specified correct value of \"columnDefs.data\" parameter in datatables options."); } } @@ -194,13 +194,13 @@ public DataTablesRequest(NameValueCollection query) } else { - throw new ArgumentException($"Could not find a property called \"{name}\" on type \"{type}\". Make sure you have specified correct value of \"columnDefs.name\" parameter in datatables options."); + throw new NoPropertyByNameException($"Could not find a property called \"{name}\" on type \"{type}\". Make sure you have specified correct value of \"columnDefs.name\" parameter in datatables options."); } } if (propertyName == null) { - throw new ArgumentException($"Unable to associate datatables column \"{colIndex}\" with model type \"{typeof(T)}\". There are no matching public property found. Make sure you specified valid identifiers for \"columnDefs.data\" and/or \"columnDefs.name\" parameters in datatables options for the column \"{colIndex}\"."); + throw new NoPropertyByNameException($"Unable to associate datatables column \"{colIndex}\" with model type \"{typeof(T)}\". There are no matching public property found. Make sure you specified valid identifiers for \"columnDefs.data\" and/or \"columnDefs.name\" parameters in datatables options for the column \"{colIndex}\"."); } var column = new DataTablesColumn() diff --git a/DataTables.Queryable/NoPropertyByNameException.cs b/DataTables.Queryable/NoPropertyByNameException.cs new file mode 100644 index 0000000..ce40089 --- /dev/null +++ b/DataTables.Queryable/NoPropertyByNameException.cs @@ -0,0 +1,9 @@ +using System; + +namespace DataTables.Queryable +{ + public class NoPropertyByNameException : Exception + { + public NoPropertyByNameException(string message) : base(message) { } + } +}