private static void CacheEnumType() { if (cachedTypeList != null) { return; } var types = BindingEditorUtility.GetAllTypeList(); cachedTypeList = types.Where(x => x.IsEnum).ToList(); }
public static List <Type> GetImplicitOperatorTypes(bool twoWay) { var dictionary = new Dictionary <Tuple <Type, Type>, MethodInfo>(); // search all types var types = BindingEditorUtility.GetAllTypeList(); foreach (var type in types) { if (!type.IsPublic) { continue; } if (type.IsGenericTypeDefinition) { continue; } var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Static); foreach (var method in methods) { if (method.Name != "op_Implicit") { continue; } var parameters = method.GetParameters(); if (parameters.Length != 1) { // with 1 parameter continue; } var parameter = parameters[0]; // add operator var key = Tuple.Create(parameter.ParameterType, method.ReturnType); dictionary.Add(key, method); } } var resultList = new List <Type>(); foreach (var item in dictionary) { var key = item.Key; if (twoWay) { var pairedKey = Tuple.Create(key.Item2, key.Item1); // check convert back MethodInfo convertBackMethod = null; dictionary.TryGetValue(pairedKey, out convertBackMethod); if (convertBackMethod == null) { // skip one-way continue; } } var type = item.Value.DeclaringType; if (!resultList.Contains(type)) { // add current type resultList.Add(type); } } return(resultList); }