Fixes with custom name setup

This commit is contained in:
Jakub Syty 2019-01-18 11:00:42 +01:00
parent bd904dff8a
commit 440ebe8cc0
4 changed files with 8 additions and 6 deletions

View File

@ -11,6 +11,8 @@ namespace Sieve.Attributes
/// </summary>
public string Name { get; set; }
public string FullName => Name;
public bool CanSort { get; set; }
public bool CanFilter { get; set; }
}

View File

@ -3,7 +3,7 @@
public interface ISievePropertyMetadata
{
string Name { get; set; }
string FullName { get; set; }
string FullName { get; }
bool CanFilter { get; set; }
bool CanSort { get; set; }
}

View File

@ -359,7 +359,7 @@ namespace Sieve.Services
if(property.Item1 == null)
{
var prop = FindPropertyBySieveAttribute<TEntity>(canSortRequired, canFilterRequired, name, _options.Value.CaseSensitive);
return (prop.Name, prop);
return (prop?.Name, prop);
}
return property;

View File

@ -32,7 +32,7 @@ namespace Sieve.Services
{
_sievePropertyMapper = sievePropertyMapper;
(_fullName, _property) = GetPropertyInfo(expression);
_name = _property.Name;
_name = _fullName;
_canFilter = false;
_canSort = false;
}
@ -97,18 +97,18 @@ namespace Sieve.Services
public (string, PropertyInfo) FindProperty<TEntity>(
bool canSortRequired,
bool canFilterRequired,
string fullName,
string name,
bool isCaseSensitive)
{
try
{
var result = _map[typeof(TEntity)]
.FirstOrDefault(kv =>
kv.Value.FullName.Equals(fullName, isCaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase)
kv.Value.Name.Equals(name, isCaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase)
&& (canSortRequired ? kv.Value.CanSort : true)
&& (canFilterRequired ? kv.Value.CanFilter : true));
return (result.Value.FullName, result.Key);
return (result.Value?.FullName, result.Key);
}
catch (Exception ex) when (ex is KeyNotFoundException || ex is ArgumentNullException)
{