@@ -209,8 +209,7 @@ public CompositeBucketAggregate Composite(string key)
209209
210210 public ValueAggregate MedianAbsoluteDeviation ( string key ) => TryGet < ValueAggregate > ( key ) ;
211211
212- private TAggregate TryGet < TAggregate > ( string key )
213- where TAggregate : class , IAggregate =>
212+ private TAggregate TryGet < TAggregate > ( string key ) where TAggregate : class , IAggregate =>
214213 BackingDictionary . TryGetValue ( key , out var agg ) ? agg as TAggregate : null ;
215214
216215 private MultiBucketAggregate < TBucket > GetMultiBucketAggregate < TBucket > ( string key )
@@ -238,19 +237,23 @@ private MultiBucketAggregate<KeyedBucket<TKey>> GetMultiKeyedBucketAggregate<TKe
238237 } ;
239238 }
240239
241-
242240 private IEnumerable < KeyedBucket < TKey > > GetKeyedBuckets < TKey > ( IEnumerable < IBucket > items )
243241 {
244242 var buckets = items . Cast < KeyedBucket < object > > ( ) ;
245243
246244 foreach ( var bucket in buckets )
247245 yield return new KeyedBucket < TKey > ( bucket . BackingDictionary )
248246 {
249- Key = ( TKey ) Convert . ChangeType ( bucket . Key , typeof ( TKey ) ) ,
247+ Key = GetKeyFromBucketKey < TKey > ( bucket . Key ) ,
250248 KeyAsString = bucket . KeyAsString ,
251249 DocCount = bucket . DocCount ,
252250 DocCountErrorUpperBound = bucket . DocCountErrorUpperBound
253251 } ;
254252 }
253+
254+ private static TKey GetKeyFromBucketKey < TKey > ( object key ) =>
255+ typeof ( TKey ) . IsEnum
256+ ? ( TKey ) Enum . Parse ( typeof ( TKey ) , key . ToString ( ) , true )
257+ : ( TKey ) Convert . ChangeType ( key , typeof ( TKey ) ) ;
255258 }
256259}
0 commit comments