I'm trying to create a method that counts the number of times a given Enum occurs within some existing dictionaries for reporting purposes:
private static Dictionary<string, int> CountEnumOccurrence(Dictionary<Enum, List<string>> valueSource)
{
var convertedDictionary = new Dictionary<string, int>();
foreach (var entry in valueSource)
{
var name = Enum.GetName(entry.Key.GetType(), entry.Key);
convertedDictionary.Add(name, entry.Value.Count);
}
return convertedDictionary;
}
However, if I attempt to call this method like so:
var criticalFailureCounts = CountEnumOccurrence(reportSpan.criticalFailures));
I get
"cannot convert from '
System.Collections.Generic.Dictionary<Reporter.CriticalFailureCategory,System.Collections.Generic.List<string>>
' to 'System.Collections.Generic.Dictionary<System.Enum,System.Collections.Generic.List<string>>
'"
Even though Reporter.CriticalFailureCategory is an Enum. I'm obviously doing this the wrong way, but I feel like there should be some way to achieve it.
Here's the definition for Reporter.CriticalFailureCategory at present:
namespace Reporter
{
[DataContract(Namespace = "")]
public enum CriticalFailureCategory
{
[EnumMember]
ExcessiveFailures,
[EnumMember]
StalledInConfiguration
}
}
The idea is that this can be expanded indefinitely without having to rewrite the code that reports on it.