Ejemplo n.º 1
0
        internal static ImmutableArray <TValue> Flatten <TKey, TValue>(
            this Dictionary <TKey, ImmutableArray <TValue> > dictionary,
            IComparer <TValue> comparer = null)
        {
            if (dictionary.Count == 0)
            {
                return(ImmutableArray <TValue> .Empty);
            }

            ArrayBuilder <TValue> builder = ArrayBuilder <TValue> .GetInstance();

            foreach (KeyValuePair <TKey, ImmutableArray <TValue> > kvp in dictionary)
            {
                builder.AddRange(kvp.Value);
            }

            if (comparer != null && builder.Count > 1)
            {
                // PERF: Beware ImmutableArray<T>.Builder.Sort allocates a Comparer wrapper object
                builder.Sort(comparer);
            }

            return(builder.ToImmutableAndFree());
        }