0
0
mirror of https://github.com/sp-tarkov/launcher.git synced 2025-02-13 09:50:43 -05:00
launcher/project/Aki.Launcher.Base/Extensions/DictionaryExtensions.cs

53 lines
1.3 KiB
C#

/* DictionaryExtension.cs
* License: NCSA Open Source License
*
* Copyright: Merijn Hendriks
* AUTHORS:
* waffle.lord
*/
using System.Collections.Generic;
using System.Linq;
namespace Aki.Launcher.Extensions
{
public static class DictionaryExtensions
{
public static TKey GetKeyByValue<TKey, TValue>(this Dictionary<TKey, TValue> dic, TValue value)
{
List<TKey> keys = dic.Keys.ToList();
for (var x = 0; x < keys.Count; x++)
{
if (dic.TryGetValue(keys[x], out var tempValue))
{
if (tempValue != null && tempValue.Equals(value))
{
return keys[x];
}
}
}
return default;
}
public static TKey GetKeyByInput<TKey, TValue>(this Dictionary<TKey, TValue> dic,
string input)
{
var keys = dic.Keys.ToList();
var values = dic.Values.ToList();
for (var x = 0; x < dic.Count; x++)
{
if (values[x] is string s && (input.ToLower() == s.ToLower() || input.ToLower().StartsWith(s.ToLower())))
{
return keys[x];
}
}
return default;
}
}
}