private IDictionary<Emotions, float> CalculateAndRankScoreToDictionary(Scores emotionScores) { if (emotionScores == null) return null; IDictionary<Emotions, float> emotionRankingDictionary = new Dictionary<Emotions, float>(); foreach (PropertyInfo prop in emotionScores.GetType().GetProperties()) { for (int index = 0; index < Enum.GetNames(typeof(Emotions)).Length; index++) { string emotionName = Enum.GetNames(typeof(Emotions))[index]; if (!prop.Name.Contains(emotionName)) { continue; } Emotions parsedEmotion = Emotions.None; Enum.TryParse(emotionName, out parsedEmotion); emotionRankingDictionary.Add(parsedEmotion, (float)prop.GetValue(emotionScores)); } } //Sort and set highest value on top return emotionRankingDictionary.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value); }
private IList<EmotionRank> CalculateAndRankScore(Scores emotionScores) { if (emotionScores == null) return null; IList<EmotionRank> emotionRankingList = new List<EmotionRank>(); foreach (PropertyInfo prop in emotionScores.GetType().GetProperties()) { for (int index = 0; index < Enum.GetNames(typeof(Emotions)).Length; index++) { string emotionName = Enum.GetNames(typeof(Emotions))[index]; if (!prop.Name.Contains(emotionName)) { continue; } Emotions parsedEmotion = Emotions.None; Enum.TryParse(emotionName, out parsedEmotion); emotionRankingList.Add(new EmotionRank() { Emotion = parsedEmotion, Rank = (float)prop.GetValue(emotionScores) }); } } //Sort and set highest value on top return emotionRankingList.OrderByDescending(x => x.Rank).ToList(); }