コード例 #1
0
        public static ExposedMethod[] GetExposedMethods(this Type type)
        {
            ExposedMethod[] result;
            if (!typeToExposedMethods.TryGetValue(type, out result))
            {
                MethodInfo[]         methods        = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                List <ExposedMethod> exposedMethods = new List <ExposedMethod>();

                for (int i = 0; i < methods.Length; i++)
                {
#if UNITY_EDITOR || !NETFX_CORE
                    if (!Attribute.IsDefined(methods[i], typeof(RuntimeInspectorButtonAttribute), true))
#else
                    if (!methods[i].IsDefined(typeof(RuntimeInspectorButtonAttribute), true))
#endif
                    { continue; }

                    if (methods[i].GetParameters().Length != 0)
                    {
                        continue;
                    }

#if UNITY_EDITOR || !NETFX_CORE
                    RuntimeInspectorButtonAttribute attribute = (RuntimeInspectorButtonAttribute)Attribute.GetCustomAttribute(methods[i], typeof(RuntimeInspectorButtonAttribute), true);
#else
                    RuntimeInspectorButtonAttribute attribute = (RuntimeInspectorButtonAttribute)methods[i].GetCustomAttribute(typeof(RuntimeInspectorButtonAttribute), true);
#endif
                    if (!attribute.IsInitializer || type.IsAssignableFrom(methods[i].ReturnType))
                    {
                        exposedMethods.Add(new ExposedMethod(methods[i], attribute, false));
                    }
                }

                for (int i = 0; i < exposedExtensionMethods.Count; i++)
                {
                    ExposedExtensionMethodHolder exposedExtensionMethod = exposedExtensionMethods[i];
                    if (exposedExtensionMethod.extendedType.IsAssignableFrom(type))
                    {
                        exposedMethods.Add(new ExposedMethod(exposedExtensionMethod.method, exposedExtensionMethod.properties, true));
                    }
                }

                if (exposedMethods.Count > 0)
                {
                    result = exposedMethods.ToArray();
                }
                else
                {
                    result = null;
                }

                typeToExposedMethods[type] = result;
            }

            return(result);
        }
コード例 #2
0
        public static ExposedMethod[] GetExposedMethods(this Type type)
        {
            ExposedMethod[] result;
            if (!typeToExposedMethods.TryGetValue(type, out result))
            {
                MethodInfo[]         methods        = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                List <ExposedMethod> exposedMethods = new List <ExposedMethod>();

                for (int i = 0; i < methods.Length; i++)
                {
//					if( !Attribute.IsDefined( methods[i], typeof( RuntimeInspectorButtonAttribute ), true ) )
//						continue;

                    if (methods[i].GetParameters().Length != 0)
                    {
                        continue;
                    }

                    RuntimeInspectorButtonAttribute attribute = (RuntimeInspectorButtonAttribute)Attribute.GetCustomAttribute(methods[i], typeof(RuntimeInspectorButtonAttribute), true);
                    XAttribute attribute1 = (XAttribute)Attribute.GetCustomAttribute(methods[i], typeof(XAttribute), true);
                    if (attribute != null && !attribute.IsInitializer || type.IsAssignableFrom(methods[i].ReturnType))
                    {
                        exposedMethods.Add(new ExposedMethod(methods[i], attribute, false));
                    }
                    if (attribute1 != null)
                    {
                        exposedMethods.Add(new ExposedMethod(methods[i], new RuntimeInspectorButtonAttribute(methods[i].Name, true, ButtonVisibility.InitializedObjects), false));
                    }
                }

                for (int i = 0; i < exposedExtensionMethods.Count; i++)
                {
                    ExposedExtensionMethodHolder exposedExtensionMethod = exposedExtensionMethods[i];
                    if (exposedExtensionMethod.extendedType.IsAssignableFrom(type))
                    {
                        exposedMethods.Add(new ExposedMethod(exposedExtensionMethod.method, exposedExtensionMethod.properties, true));
                    }
                }

                if (exposedMethods.Count > 0)
                {
                    result = exposedMethods.ToArray();
                }
                else
                {
                    result = null;
                }

                typeToExposedMethods[type] = result;
            }

            return(result);
        }
コード例 #3
0
        public static ExposedMethod[] GetExposedMethods(this Type type)
        {
            ExposedMethod[] result;
            if (!typeToExposedMethods.TryGetValue(type, out result))
            {
                MethodInfo[] methods = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

                exposedMethodsList.Clear();
                for (int i = 0; i < methods.Length; i++)
                {
                    if (!methods[i].HasAttribute <RuntimeInspectorButtonAttribute>())
                    {
                        continue;
                    }

                    if (methods[i].GetParameters().Length != 0)
                    {
                        continue;
                    }

                    RuntimeInspectorButtonAttribute attribute = methods[i].GetAttribute <RuntimeInspectorButtonAttribute>();
                    if (!attribute.IsInitializer || type.IsAssignableFrom(methods[i].ReturnType))
                    {
                        exposedMethodsList.Add(new ExposedMethod(methods[i], attribute, false));
                    }
                }

                for (int i = 0; i < exposedExtensionMethods.Count; i++)
                {
                    ExposedExtensionMethodHolder exposedExtensionMethod = exposedExtensionMethods[i];
                    if (exposedExtensionMethod.extendedType.IsAssignableFrom(type))
                    {
                        exposedMethodsList.Add(new ExposedMethod(exposedExtensionMethod.method, exposedExtensionMethod.properties, true));
                    }
                }

                if (exposedMethodsList.Count > 0)
                {
                    result = exposedMethodsList.ToArray();
                }
                else
                {
                    result = null;
                }

                typeToExposedMethods[type] = result;
            }

            return(result);
        }