public virtual void DumpProperties() { var properties = this.GetType().GetProperties(); //remember to tag [BaseAddress] var entityBase = properties.Single(p => p.HasAttribute <BaseAddressAttribute>()); Prettify(entityBase).Dump(); var baseDepth = (entityBase.GetValue(this, null) as PointerBase).GetDepth(); var entityPropertyies = properties.Where(p => !p.HasAttribute <BaseAddressAttribute>()) .Where(p => typeof(PointerBase).IsAssignableFrom(p.PropertyType)) /*.OrderBy(p => * { * var pointer = p.GetValue(this, null) as PointerBase; * return pointer.GetOffsets(pointer.GetDepth() - baseDepth); * })*/; using (Indentation.Indent()) { int padding = entityPropertyies.Max(x => x.Name.Length); foreach (var property in entityPropertyies) { Prettify(property, baseDepth, padding).Dump(); } } Environment.NewLine.Dump(); }
/// <summary> /// Generates the help message based on the declaration of the command line. /// </summary> /// <param name="commandLine">Corresponding command-line declaration</param> /// <returns>string to be readily output</returns> public static string GenerateUsageMessage(CommandLine commandLine) { var blocks = new List <string>(); // # Description if (commandLine.Description.Length > 0) { var writer = new System.IO.StringWriter(); writer.WriteLine($"{commandLine.Name}:"); writer.WriteLine(Indentation.Indent(commandLine.Description, " ")); blocks.Add(writer.ToString()); } else { blocks.Add("{commandLine.Name}:"); } // # Usage if (commandLine.Commands.Count == 0) { blocks.Add($"Usage: {commandLine.Name}"); } else { var writer = new System.IO.StringWriter(); writer.WriteLine("Usage:"); writer.WriteLine($" {commandLine.Name} [list of commands]"); blocks.Add(writer.ToString()); } // # Commands if (commandLine.Commands.Count > 0) { var writer = new System.IO.StringWriter(); writer.WriteLine("Commands:"); var cmdBlocks = new List <string>(); foreach (var cmd in commandLine.Commands) { var cmdWriter = new System.IO.StringWriter(); string args = ((cmd.Arguments.Count > 0) // Prefix with the space only if there are any arguments ? " " : "") + string.Join( " ", cmd.Arguments.Select(arg => $"[{arg.Name}]") ); cmdWriter.WriteLine($" {cmd.Name}{args}"); cmdWriter.WriteLine(Indentation.Indent(cmd.Description, " ")); foreach (var arg in cmd.Arguments) { cmdWriter.WriteLine(); cmdWriter.WriteLine($" {arg.Name}:"); cmdWriter.WriteLine(Indentation.Indent(arg.Description, " ")); } cmdBlocks.Add(cmdWriter.ToString()); } writer.Write(string.Join(System.Environment.NewLine, cmdBlocks)); blocks.Add(writer.ToString()); } // # Join the blocks string result = string.Join(System.Environment.NewLine, blocks); return(result); }