diff --git a/Sieve/Exceptions/SieveIncompatibleMethodException.cs b/Sieve/Exceptions/SieveIncompatibleMethodException.cs new file mode 100644 index 0000000..4aefb4d --- /dev/null +++ b/Sieve/Exceptions/SieveIncompatibleMethodException.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Sieve.Exceptions +{ + public class SieveIncompatibleMethodException : Exception + { + public string MethodName { get; protected set; } + public Type ExpectedType { get; protected set; } + public Type ActualType { get; protected set; } + + + public SieveIncompatibleMethodException( + string methodName, + Type expectedType, + Type actualType, + string message) + : base(message) + { + MethodName = methodName; + ExpectedType = expectedType; + ActualType = actualType; + } + + public SieveIncompatibleMethodException( + string methodName, + Type expectedType, + Type actualType, + string message, + Exception innerException) + : base(message, innerException) + { + MethodName = methodName; + ExpectedType = expectedType; + ActualType = actualType; + } + } +} diff --git a/Sieve/Exceptions/SieveMethodNotFoundException.cs b/Sieve/Exceptions/SieveMethodNotFoundException.cs new file mode 100644 index 0000000..ea9c345 --- /dev/null +++ b/Sieve/Exceptions/SieveMethodNotFoundException.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Sieve.Exceptions +{ + public class SieveMethodNotFoundException : Exception + { + public string MethodName { get; protected set; } + + public SieveMethodNotFoundException(string methodName, string message) : base (message) + { + MethodName = methodName; + } + + public SieveMethodNotFoundException(string methodName, string message, Exception innerException) : base(message, innerException) + { + MethodName = methodName; + } + } +} diff --git a/Sieve/Services/SieveProcessor.cs b/Sieve/Services/SieveProcessor.cs index d168102..8d998dd 100644 --- a/Sieve/Services/SieveProcessor.cs +++ b/Sieve/Services/SieveProcessor.cs @@ -11,6 +11,7 @@ using Sieve.Extensions; using System.ComponentModel; using System.Collections; using System.Linq.Expressions; +using Sieve.Exceptions; namespace Sieve.Services { @@ -294,7 +295,6 @@ namespace Sieve.Services result = customMethod.Invoke(parent, parameters) as IQueryable; } - catch (ArgumentException) { } // name matched with custom emthod for a differnt type catch (TargetParameterCountException) { if (optionalParameters != null) @@ -307,6 +307,18 @@ namespace Sieve.Services throw; } } + catch (ArgumentException) // name matched with custom method for a differnt type + { + var expected = typeof(TEntity); + var actual = ((IQueryable)customMethod.ReturnParameter).ElementType; + throw new SieveIncompatibleMethodException(name, expected, actual, + $"{name} failed. Expected a custom method for type {expected} but only found for type {actual}"); + } + } + else + { + throw new SieveMethodNotFoundException(name, + $"{name} not found."); } return result; diff --git a/Sieve/Sieve.nuspec b/Sieve/Sieve.nuspec index de57c52..868358a 100644 --- a/Sieve/Sieve.nuspec +++ b/Sieve/Sieve.nuspec @@ -2,7 +2,7 @@ Sieve - 1.3.9 + 1.3.91 Sieve Biarity Biarity @@ -13,7 +13,7 @@ Sieve is a simple, clean, and extensible framework for .NET Core that adds sorting, filtering, and pagination functionality out of the box. Most common use case would be for serving ASP.NET Core GET queries. Documentation available on GitHub: https://github.com/Biarity/Sieve/ - Fluent API v1 and case-insensitive operators + Custom method case-insensitivity Copyright 2018 aspnetcore filter sort page paginate sieve search