Exemple #1
0
 public NodeMethodAttribute(string category, string name, NodeMethodType type, string outputName = "Output")
 {
     m_category   = category;
     m_name       = name;
     m_type       = type;
     m_outputName = outputName;
 }
        static private NodeSetData RetrieveNodeMethods(NodeMethodType filter)
        {
            NodeMethodAttribute[] nodeMethodsAttribute;
            MethodInfo[]          nodeMethodsInfo = NodeMethodAttribute.GetNodeMethods(out nodeMethodsAttribute, filter);

            List <string> categories = GetNodeCategories(nodeMethodsAttribute);

            categories.Sort();

            List <NodeMethodAttribute>[] attributesByCategory = new List <NodeMethodAttribute> [categories.Count];
            List <MethodInfo>[]          methodsByCategory    = new List <MethodInfo> [categories.Count];
            for (int i = 0; i < categories.Count; i++)
            {
                attributesByCategory[i] = new List <NodeMethodAttribute>();
                methodsByCategory[i]    = new List <MethodInfo>();
            }

            for (int i = 0; i < nodeMethodsAttribute.Length; i++)
            {
                int categoryIndex = categories.IndexOf(nodeMethodsAttribute[i].category);
                attributesByCategory[categoryIndex].Add(nodeMethodsAttribute[i]);
                methodsByCategory[categoryIndex].Add(nodeMethodsInfo[i]);
            }

            List <string> filteredCategories = new List <string>(categories.Count);
            List <NodeMethodAttribute[]> filteredNodeMethodsAttributes = new List <NodeMethodAttribute[]>(categories.Count);
            List <MethodInfo[]>          filteredNodeMethods           = new List <MethodInfo[]>(categories.Count);

            for (int i = 0; i < categories.Count; i++)
            {
                if (!categories[i].StartsWith("Hidden"))
                {
                    filteredCategories.Add(categories[i]);
                    filteredNodeMethodsAttributes.Add(attributesByCategory[i].ToArray());
                    filteredNodeMethods.Add(methodsByCategory[i].ToArray());
                }
            }

            return(new NodeSetData
            {
                nodeMethodsAttributes = filteredNodeMethodsAttributes.ToArray(),
                nodeMethods = filteredNodeMethods.ToArray(),
                nodeCategories = filteredCategories.ToArray()
            });
        }
Exemple #3
0
        static public MethodInfo[] GetNodeMethods(out NodeMethodAttribute[] nodeMethodsAttribute, NodeMethodType filter)
        {
            List <MethodInfo>          resultMethodsInfo = new List <MethodInfo>();
            List <NodeMethodAttribute> resultAttributes  = new List <NodeMethodAttribute>();

            Type[] types = Assembly.GetExecutingAssembly().GetTypes();

            foreach (Type type in types)
            {
                MethodInfo[] allMethodsOfType = type.GetMethods();
                foreach (MethodInfo methodInfo in allMethodsOfType)
                {
                    if (methodInfo.DeclaringType != methodInfo.ReflectedType)
                    {
                        continue;
                    }

                    object[] methodAttributes = methodInfo.GetCustomAttributes(typeof(NodeMethodAttribute), true);
                    if (methodAttributes.Length > 0)
                    {
                        NodeMethodAttribute nodeMethodAttribute = (NodeMethodAttribute)methodAttributes[0];
                        if ((nodeMethodAttribute.m_type & filter) != nodeMethodAttribute.m_type)
                        {
                            continue;
                        }

                        resultMethodsInfo.Add(methodInfo);
                        resultAttributes.Add(nodeMethodAttribute);
                    }
                }
            }

            nodeMethodsAttribute = resultAttributes.ToArray();
            return(resultMethodsInfo.ToArray());
        }