123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- #if UNITY_WSA && !UNITY_EDITOR && !ENABLE_IL2CPP
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Reflection;
-
- namespace System.TypeFix
- {
- public static class ReflectionHelpers
- {
-
-
-
-
-
-
-
-
-
-
- public static bool IsInstanceOfType(this Type type, object o)
- {
- return o != null && type.IsAssignableFrom(o.GetType());
- }
- internal static bool ImplementInterface(this Type type, Type ifaceType)
- {
- while (type != null)
- {
- Type[] interfaces = type.GetTypeInfo().ImplementedInterfaces.ToArray();
- if (interfaces != null)
- {
- for (int i = 0; i < interfaces.Length; i++)
- {
- if (interfaces[i] == ifaceType || (interfaces[i] != null && interfaces[i].ImplementInterface(ifaceType)))
- {
- return true;
- }
- }
- }
- type = type.GetTypeInfo().BaseType;
-
- }
- return false;
- }
- public static bool IsAssignableFrom(this Type type, Type c)
- {
- if (c == null)
- {
- return false;
- }
- if (type == c)
- {
- return true;
- }
-
-
-
-
-
-
- if (c.GetTypeInfo().IsSubclassOf(c))
- {
- return true;
- }
-
- if (type.GetTypeInfo().IsInterface)
- {
- return c.ImplementInterface(type);
- }
- if (type.IsGenericParameter)
- {
- Type[] genericParameterConstraints = type.GetTypeInfo().GetGenericParameterConstraints();
- for (int i = 0; i < genericParameterConstraints.Length; i++)
- {
- if (!genericParameterConstraints[i].IsAssignableFrom(c))
- {
- return false;
- }
- }
- return true;
- }
- return false;
- }
- public static bool IsEnum(this Type type)
- {
- return type.GetTypeInfo().IsEnum;
- }
- }
- }
- #endif
- #endif
|