Example #1
0
 private CommandTreeNode FillTreeNode(CommandTreeNode node, Command command, CommandTreeNode nodeAfter)
 {
     Type type = command.GetType();
     var commandAttr = type.GetCustomAttributes(false).OfType<GinNameAttribute>().FirstOrDefault();
     CommandTreeNode commandNode;
     if (nodeAfter == null)
     {
         commandNode = node.AppendChild(command, commandAttr);
     }
     else
     {
         commandNode = node.InsertAfter(command, commandAttr, nodeAfter);
     }
     var properties = type.GetProperties();
     foreach (PropertyInfo property in properties)
     {
         var propertyAttr = (GinArgumentCommandAttribute)property.GetCustomAttributes(typeof(GinArgumentCommandAttribute), false).FirstOrDefault();
         if (propertyAttr != null)
         {
             CommandTreeNode argumentNode = commandNode.AppendChild(command, commandAttr, property, propertyAttr);
             object nestedCommand = property.GetValue(command, null);
             if (nestedCommand != null)
             {
                 Type nestedType = nestedCommand.GetType();
                 bool isEnumerable = propertyAttr.IsEnumerable;
                 if (isEnumerable)
                 {
                     IEnumerable iEnum = (IEnumerable)nestedCommand;
                     foreach (var item in iEnum)
                     {
                         FillTreeNode(argumentNode, (Command)item, null);
                     }
                 }
                 else
                 {
                     FillTreeNode(argumentNode, (Command)nestedCommand, null);
                 }
             }
         }
     }
     return commandNode;
 }