/// <summary> /// Returns an array of <see cref="ConsoleCommand"/>s /// </summary> /// <param name="methods"></param> /// <returns></returns> private ConsoleCommand[] GetConsoleCommands(MethodInfo[] methods) { List <ConsoleCommand> cmds = new List <ConsoleCommand>(); for (int i = 0; i < methods.Length; i++) { ConsoleCommand cmd = Attribute.GetCustomAttribute(methods[i], typeof(ConsoleCommand)) as ConsoleCommand; if (cmd != null) { cmds.Add(cmd); } } return(cmds.ToArray()); }
/// <summary> /// Returns true if a method is a console command /// </summary> /// <param name="method"></param> /// <returns></returns> private bool IsConsoleCommand(MethodInfo method) { ConsoleCommand cmd = Attribute.GetCustomAttribute(method, typeof(ConsoleCommand)) as ConsoleCommand; return((cmd == null) ? false : true); }
private void ConstructNodeTree() { //List<MethodInfo> methods = new List<MethodInfo>(); //for (int i = 0; i < methodData.Length; i++) //{ // methods.AddRange(methodData[i].methods); //} //MethodInfo[] me = GetMethodData(); for (int m = 0; m < methodData.Length; m++) { for (int i = 0; i < methodData[m].methods.Count; i++) { ConsoleCommand command = GetConsoleCommand(methodData[m].methods[i]); if (command != null) { // Custom path if (command.customPath != "") { string[] split = command.customPath.Split('.'); List <CLINode> currentNodeList = nodes; for (int splitIndex = 0; splitIndex < split.Length; splitIndex++) { CLINode n = new CLINode(); n = GetNode(currentNodeList, split[splitIndex]); if (n == null) { n = new CLINode(); n.name = split[splitIndex]; currentNodeList.Add(n); } currentNodeList = n.children; if (splitIndex == split.Length - 1) { CLINode finalNode = new CLINode(); finalNode.name = methodData[m].methods[i].Name; finalNode.method = methodData[m].methods[i]; finalNode.monoBehaviour = methodData[m].monoBehaviour; n.children.Add(finalNode); } } } // Type path CLINode childNode = new CLINode(); childNode.name = methodData[m].methods[i].Name; childNode.method = methodData[m].methods[i]; childNode.monoBehaviour = methodData[m].monoBehaviour; string baseNodeName = methodData[m].methods[i].DeclaringType.ToString(); CLINode baseNode = GetNode(nodes, baseNodeName); if (baseNode != null) { // Base node exists baseNode.children.Add(childNode); } else { // Base node doesn't exist baseNode = new CLINode(); baseNode.name = methodData[m].methods[i].DeclaringType.ToString(); baseNode.children.Add(childNode); nodes.Add(baseNode); } } } } }