/// <summary> /// WSA support /// </summary> /// <param name="t"></param> /// <returns></returns> public static bool IsEnum(this Type t) { #if UNITY_WSA return(ReflectionCache.Get(t).TypeInfo.IsEnum); #else return(t.IsEnum); #endif }
/// <summary> /// WSA support /// </summary> /// <returns></returns> public static bool IsAssignable(this Type desiredType, object param) { #if UNITY_WSA var d = ReflectionCache.Get(desiredType).TypeInfo; var i = ReflectionCache.Get(param.GetType()).TypeInfo; return(d.IsAssignableFrom(i)); #else return(desiredType.IsInstanceOfType(param)); #endif }
/// <summary> /// return Attribute.IsDefined(m, typeof(T)); /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static T GetAttribute <T>(this object m, string memberName) where T : Attribute { var member = ReflectionCache.Get <T>().GetMember(memberName); if (member == null) { return(null); } return(member.GetAttribute <T>()); }
/// <summary> /// Set the member's instances value /// </summary> /// <returns></returns> public static object GetMemberValue(this object instance, string propertyName) { var member = ReflectionCache.Get(instance.GetType()).GetMember(propertyName); if (member == null) { return(null); } if (member is MethodInfo) { return(((MethodInfo)member).Invoke(instance, null)); } if (member is PropertyInfo) { return(((PropertyInfo)member).GetValue(instance, null)); } return(((FieldInfo)member).GetValue(instance)); }
/// <summary> /// Get Member /// </summary> /// <param name="t"></param> /// <param name="name"></param> /// <returns></returns> public static MemberInfo GetRuntimeMember(this Type t, string name) { return(ReflectionCache.Get(t).GetMember(name)); }
/// <summary> /// Get all Members /// </summary> /// <param name="t"></param> /// <returns></returns> public static MemberInfo[] GetRuntimeMembers(this Type t) { return(ReflectionCache.Get(t).Members); }