0
0
mirror of https://github.com/sp-tarkov/launcher.git synced 2025-02-13 05:10:45 -05:00
launcher/project/SPT.Launcher.Base/Extensions/DictionaryExtensions.cs

53 lines
1.3 KiB
C#
Raw Normal View History

2023-03-03 19:25:33 +00:00
/* DictionaryExtension.cs
* License: NCSA Open Source License
*
2024-05-21 20:15:19 +01:00
* Copyright: SPT
2023-03-03 19:25:33 +00:00
* AUTHORS:
* waffle.lord
*/
using System.Collections.Generic;
using System.Linq;
2024-05-21 20:15:19 +01:00
namespace SPT.Launcher.Extensions
2023-03-03 19:25:33 +00:00
{
public static class DictionaryExtensions
{
public static TKey GetKeyByValue<TKey, TValue>(this Dictionary<TKey, TValue> dic, TValue value)
2023-03-03 19:25:33 +00:00
{
List<TKey> keys = dic.Keys.ToList();
2023-03-03 19:25:33 +00:00
for (var x = 0; x < keys.Count; x++)
2023-03-03 19:25:33 +00:00
{
if (dic.TryGetValue(keys[x], out var tempValue))
2023-03-03 19:25:33 +00:00
{
if (tempValue != null && tempValue.Equals(value))
{
return keys[x];
2023-03-03 19:25:33 +00:00
}
}
}
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;
}
2023-03-03 19:25:33 +00:00
}
}