예제 #1
0
        public static MethodInfoSorter GetMethodsWithAttribute <T>(BindingFlags bindingFlags = kAllStatic) where T : Attribute
        {
            MethodInfoSorter result;

            if (!s_DecoratedMethodsByAttrTypeCache.TryGetValue(typeof(T), out result))
            {
                var tmp = new List <MethodWithAttribute>();
                foreach (var method in EditorAssemblies.GetAllMethodsWithAttribute <T>(bindingFlags))
                {
                    if (method.IsGenericMethod)
                    {
                        Debug.LogErrorFormat($"{MethodToString(method)} is a generic method. {typeof(T)} cannot be applied to it.");
                    }
                    else
                    {
                        foreach (var attr in method.GetCustomAttributes(typeof(T), false))
                        {
                            var methodWithAttribute = new MethodWithAttribute {
                                info = method, attribute = (T)attr
                            };
                            tmp.Add(methodWithAttribute);
                        }
                    }
                }

                result = new MethodInfoSorter(tmp);
                s_DecoratedMethodsByAttrTypeCache[typeof(T)] = result;
            }
            return(result);
        }
예제 #2
0
 static void Test2()
 {
     EditorAssemblies.GetAllMethodsWithAttribute <ToolProviderAttribute>();
 }