Line data Source code
1 : using System;
2 : using System.Collections.Generic;
3 : using System.Linq;
4 :
5 : namespace Cqrs.Repositories.Queries
6 : {
7 : public static class QueryPredicateExtensions
8 0 : {
9 0 : public static TResult GetValue<TResult>(this KeyValuePair<string, object> keyValuePair)
10 : {
11 : return (TResult) keyValuePair.Value;
12 : }
13 :
14 0 : public static TResult GetValue<TResult>(this ISet<KeyValuePair<string, object>> collection, string key)
15 : {
16 : return collection.Single(kvp => kvp.Key == key).GetValue<TResult>();
17 : }
18 :
19 0 : public static TResult GetValue<TResult>(this SortedSet<KeyValuePair<string, object>> collection, int index)
20 : {
21 : int collectionIndex = 0;
22 : foreach (KeyValuePair<string, object> keyValuePair in collection)
23 : {
24 : if (index < collectionIndex++)
25 : continue;
26 : return keyValuePair.GetValue<TResult>();
27 : }
28 : throw new IndexOutOfRangeException();
29 : }
30 :
31 0 : public static TResult GetValue<TResult>(this QueryParameter queryParameter)
32 : {
33 : return (TResult)queryParameter.ParameterValue;
34 : }
35 :
36 0 : public static TResult GetValue<TResult>(this ISet<QueryParameter> collection, string parameterName)
37 : {
38 : return collection.Single(queryParameter => queryParameter.ParameterName == parameterName).GetValue<TResult>();
39 : }
40 :
41 0 : public static TResult GetValue<TResult>(this SortedSet<QueryParameter> collection, int index)
42 : {
43 : int collectionIndex = 0;
44 : foreach (QueryParameter queryParameter in collection)
45 : {
46 : if (index < collectionIndex++)
47 : continue;
48 : return queryParameter.GetValue<TResult>();
49 : }
50 : throw new IndexOutOfRangeException();
51 : }
52 :
53 0 : public static TResult GetValue<TResult>(this SortedSet<QueryParameter> collection, string parameterName)
54 : {
55 : return collection.Single(queryParameter => queryParameter.ParameterName == parameterName).GetValue<TResult>();
56 : }
57 : }
58 : }
|