Applitools.Utils.CommonUtils.ConvertDictionaryKeys C# (CSharp) Method

ConvertDictionaryKeys() public static method

public static ConvertDictionaryKeys ( Dictionary obj ) : TVal>.Dictionary
obj Dictionary
return TVal>.Dictionary
        public static Dictionary<TKey, TVal> ConvertDictionaryKeys<TKey, TVal>(Dictionary<string, TVal> obj) where TKey : struct
        {
            Dictionary<TKey, TVal> result = new Dictionary<TKey, TVal>();
            TKey[] collection = (TKey[])Enum.GetValues(typeof(TKey));
            HashSet<TKey> values = new HashSet<TKey>(collection);
            foreach (var entry in obj)
            {
                TKey? success = null;
                foreach (TKey val in values)
                {
                    string name = val.GetAttribute<EnumMemberAttribute>().Value;
                    if (entry.Key.Equals(name, StringComparison.OrdinalIgnoreCase))
                    {
                        result.Add(val, entry.Value);
                        success = val;
                        break;
                    }
                }
                if (success != null) values.Remove(success.Value);
            }
            return result;
        }