mirror of
https://github.com/chylex/Code-Statistics.git
synced 2024-11-24 12:42:46 +01:00
21 lines
751 B
C#
21 lines
751 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace CodeStatisticsCore.Collections{
|
|
public static class EnumDictionary{
|
|
/// <summary>
|
|
/// Creates a Dictionary<Enum, TValue> and prefills it with <paramref name="initializeTo"/> assigned to each element of the Enum.
|
|
/// </summary>
|
|
public static Dictionary<TKey, TValue> Create<TKey, TValue>(TValue initializeTo = default(TValue)) where TKey : struct{
|
|
Array values = Enum.GetValues(typeof(TKey));
|
|
Dictionary<TKey, TValue> dict = new Dictionary<TKey, TValue>(values.Length);
|
|
|
|
foreach(object value in values){
|
|
dict[(TKey)value] = initializeTo;
|
|
}
|
|
|
|
return dict;
|
|
}
|
|
}
|
|
}
|