зеркало из https://github.com/Azure/Sia-Root.git
Merge pull request #28 from pdimitratos/features/filterSignalR
Altering filters to allow for bidirectional matching (single event ma…
This commit is contained in:
Коммит
0af98812e5
|
@ -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);
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче