add all
This commit is contained in:
50
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/util/Enums.cs
vendored
Normal file
50
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/util/Enums.cs
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.Date;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities
|
||||
{
|
||||
internal static class Enums
|
||||
{
|
||||
internal static TEnum GetEnumValue<TEnum>(string s)
|
||||
where TEnum : struct, Enum
|
||||
{
|
||||
// We only want to parse single named constants
|
||||
if (s.Length > 0 && char.IsLetter(s[0]) && s.IndexOf(',') < 0)
|
||||
{
|
||||
s = s.Replace('-', '_');
|
||||
s = s.Replace('/', '_');
|
||||
|
||||
#if NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return Enum.Parse<TEnum>(s, false);
|
||||
#else
|
||||
return (TEnum)Enum.Parse(typeof(TEnum), s, false);
|
||||
#endif
|
||||
}
|
||||
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
internal static TEnum[] GetEnumValues<TEnum>()
|
||||
where TEnum : struct, Enum
|
||||
{
|
||||
#if NET5_0_OR_GREATER
|
||||
return Enum.GetValues<TEnum>();
|
||||
#else
|
||||
return (TEnum[])Enum.GetValues(typeof(TEnum));
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static TEnum GetArbitraryValue<TEnum>()
|
||||
where TEnum : struct, Enum
|
||||
{
|
||||
TEnum[] values = GetEnumValues<TEnum>();
|
||||
int pos = (int)(DateTimeUtilities.CurrentUnixMs() & int.MaxValue) % values.Length;
|
||||
return values[pos];
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
Reference in New Issue
Block a user