Merge pull request #28 from pdimitratos/features/filterSignalR

Altering filters to allow for bidirectional matching (single event ma…
This commit is contained in:
pdimitratos 2018-03-15 16:00:22 -07:00 коммит произвёл GitHub
Родитель 75ecf971e1 6f7db69f04
Коммит 0af98812e5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 27 добавлений и 10 удалений

Просмотреть файл

@ -7,29 +7,26 @@ using System.Text;
namespace Sia.Shared.Data
{
public interface IQueryFilterer<T>
public interface IFilterByMatch<T>
{
IQueryable<T> Filter(IQueryable<T> source);
bool IsMatchFor(T toCompare);
}
public interface IFilterMetadataProvider
{
IEnumerable<KeyValuePair<string, string>> FilterValues();
}
public abstract class Filters<T>
: IQueryFilterer<T>,
public interface IFilters<T>
: IFilterByMatch<T>,
IFilterMetadataProvider
{
public abstract IQueryable<T> Filter(IQueryable<T> source);
public abstract IEnumerable<KeyValuePair<string, string>> FilterValues();
}
{}
}
namespace System.Linq
{
public static class FilterExtensions
{
public static IQueryable<T> WithFilter<T>(this IQueryable<T> source, IQueryFilterer<T> filter)
=> filter.Filter(source);
public static IQueryable<T> WithFilter<T>(this IQueryable<T> source, IFilterByMatch<T> filter)
=> source.Where(t => filter.IsMatchFor(t));
}
}

Просмотреть файл

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace System.Collections.Concurrent
{
public static class ConcurrentCollectionExtensions
{
/// <summary>
/// Minor wrapper around AddOrUpdate inteded for use when the passed in value should
/// always override the existing value in the dictionary.
/// </summary>
/// <returns>The final value in the concurrent dictionary (which may not be the passed in expected final value)</returns>
public static TValue Upsert<TKey, TValue>(
this ConcurrentDictionary<TKey, TValue> dictionary,
TKey keyToUpdate,
TValue intendedFinalValue
) => dictionary.AddOrUpdate(keyToUpdate, intendedFinalValue, (key, value) => intendedFinalValue);
}
}