Пример #1
0
        private TAggregate TryGet <TAggregate>(string key)
            where TAggregate : class, IAggregate
        {
            IAggregate agg;

            return(BackingDictionary.TryGetValue(key, out agg) ? agg as TAggregate : null);
        }
        public TermsAggregate <TKey> Terms <TKey>(string key)
        {
            if (!BackingDictionary.TryGetValue(key, out var agg))
            {
                return(null);
            }

            switch (agg)
            {
            case EmptyTermsAggregate empty:
                return(new TermsAggregate <TKey>
                {
                    Buckets = Array.Empty <TermsBucket <TKey> >().ToReadOnlyCollection(),
                    Meta = empty.Meta,
                    DocCountErrorUpperBound = empty.DocCountErrorUpperBound,
                    SumOtherDocCount = empty.SumOtherDocCount
                });

            case StringTermsAggregate stringTerms:
                var buckets = stringTerms.Buckets.Select(b => new TermsBucket <TKey> {
                    DocCount = b.DocCount, DocCountError = b.DocCountError, Key = GetKeyFromBucketKey <TKey>(b.Key), KeyAsString = b.Key
                }).ToReadOnlyCollection();
                return(new TermsAggregate <TKey>
                {
                    Buckets = buckets,
                    Meta = stringTerms.Meta,
                    DocCountErrorUpperBound = stringTerms.DocCountErrorUpperBound,
                    SumOtherDocCount = stringTerms.SumOtherDocCount
                });

            case DoubleTermsAggregate doubleTerms:
                var doubleTermsBuckets = doubleTerms.Buckets.Select(b => new TermsBucket <TKey> {
                    DocCount = b.DocCount, DocCountError = b.DocCountError, Key = GetKeyFromBucketKey <TKey>(b.Key), KeyAsString = b.KeyAsString
                }).ToReadOnlyCollection();
                return(new TermsAggregate <TKey>
                {
                    Buckets = doubleTermsBuckets,
                    Meta = doubleTerms.Meta,
                    DocCountErrorUpperBound = doubleTerms.DocCountErrorUpperBound,
                    SumOtherDocCount = doubleTerms.SumOtherDocCount
                });

            case LongTermsAggregate longTerms:
                var longTermsBuckets = longTerms.Buckets.Select(b => new TermsBucket <TKey> {
                    DocCount = b.DocCount, DocCountError = b.DocCountError, Key = GetKeyFromBucketKey <TKey>(b.Key), KeyAsString = b.KeyAsString
                }).ToReadOnlyCollection();
                return(new TermsAggregate <TKey>
                {
                    Buckets = longTermsBuckets,
                    Meta = longTerms.Meta,
                    DocCountErrorUpperBound = longTerms.DocCountErrorUpperBound,
                    SumOtherDocCount = longTerms.SumOtherDocCount
                });

                // TODO - Multi-terms
            }

            return(null);
        }
Пример #3
0
    public bool TryGetProperty <T>(PropertyName propertyName, out T property) where T : PropertyBase
    {
        if (BackingDictionary.TryGetValue(propertyName, out var propertyBase) && propertyBase is T finalProperty)
        {
            property = finalProperty;
            return(true);
        }

        property = default;
        return(false);
    }
        public bool TryGetStringTerms(string key, out StringTermsAggregate?aggregate)
        {
            aggregate = null;

            if (BackingDictionary.TryGetValue(key, out var agg) && agg is StringTermsAggregate stringTermsAgg)
            {
                aggregate = stringTermsAgg;
                return(true);
            }

            return(false);
        }
Пример #5
0
 /// <summary>
 ///     <see cref="Dictionary{TKey,TValue}.TryGetValue"/>
 /// </summary>
 public bool TryGetValue([NotNull] TKey key, out TItem item) => BackingDictionary.TryGetValue(key, out item);
Пример #6
0
 private TAggregate TryGet <TAggregate>(string key) where TAggregate : class, IAggregate =>
 BackingDictionary.TryGetValue(key, out var agg) ? agg as TAggregate : null;
 public bool TryGetValue(TKey key, out TValue value) =>
 BackingDictionary.TryGetValue(Sanitize(key), out value);
 public TValue this[string key] => BackingDictionary.TryGetValue(key, out var v) ? v : default(TValue);
 public TValue this[TKey key] => BackingDictionary.TryGetValue(Sanitize(key), out var v) ? v : default(TValue);
 public bool IsEmptyTerms(string key) => !BackingDictionary.TryGetValue(key, out var agg) || agg is EmptyTermsAggregate;