培训考核三期,新版培训,网页版培训登录器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.6 KiB

#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Text;
#if NETCF_1_0 || NETCF_2_0 || SILVERLIGHT || PORTABLE || NETFX_CORE
using System.Collections;
using System.Reflection;
#endif
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Date;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities
{
internal abstract class Enums
{
internal static Enum GetEnumValue(System.Type enumType, string s)
{
if (!IsEnumType(enumType))
throw new ArgumentException("Not an enumeration type", "enumType");
// 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 NETCF_1_0
FieldInfo field = enumType.GetField(s, BindingFlags.Static | BindingFlags.Public);
if (field != null)
{
return (Enum)field.GetValue(null);
}
#else
return (Enum)Enum.Parse(enumType, s, false);
#endif
}
throw new ArgumentException();
}
internal static Array GetEnumValues(System.Type enumType)
{
if (!IsEnumType(enumType))
throw new ArgumentException("Not an enumeration type", "enumType");
#if NETCF_1_0 || NETCF_2_0 || SILVERLIGHT
IList result = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
FieldInfo[] fields = enumType.GetFields(BindingFlags.Static | BindingFlags.Public);
foreach (FieldInfo field in fields)
{
// Note: Argument to GetValue() ignored since the fields are static,
// but Silverlight for Windows Phone throws exception if we pass null
result.Add(field.GetValue(enumType));
}
object[] arr = new object[result.Count];
result.CopyTo(arr, 0);
return arr;
#else
return Enum.GetValues(enumType);
#endif
}
internal static Enum GetArbitraryValue(System.Type enumType)
{
Array values = GetEnumValues(enumType);
int pos = (int)(DateTimeUtilities.CurrentUnixMs() & int.MaxValue) % values.Length;
return (Enum)values.GetValue(pos);
}
internal static bool IsEnumType(System.Type t)
{
#if NEW_REFLECTION || NETFX_CORE
return t.GetTypeInfo().IsEnum;
#else
return t.IsEnum;
#endif
}
}
}
#pragma warning restore
#endif