public string GenerateClass(string @namespace, FlatType type) { List <string> mixinTypes = type.RequiredMixin() .Select(mixin => mixin.Name) .ToList(); var builder = new StringBuilder(); builder.AppendLine($"namespace Maple2.File.Flat.{@namespace} {{"); List <string> mixinInterfaces = mixinTypes.Select(mixin => $"I{mixin}").ToList(); if (mixinInterfaces.Count > 0) { builder.AppendLine($"\tpublic class {type.Name} : {string.Join(",", mixinInterfaces)} {{"); } else { builder.AppendLine($"\tpublic class {type.Name} : IMapEntity {{"); } builder.AppendLine($"\t\tstring ModelName => \"{type.Name}\";"); foreach (FlatProperty property in type.GetProperties()) { string typeStr = NormalizeType(property.Value.GetType().ToString()); string typeValue = property.ValueCodeString(); builder.AppendLine($"\t\tpublic {typeStr} {property.Name} {{ get; set; }} = {typeValue};"); } foreach (FlatProperty property in type.GetInheritedProperties()) { string typeStr = NormalizeType(property.Value.GetType().ToString()); string typeValue = property.ValueCodeString(); builder.AppendLine($"\t\t{typeStr} {property.Name} {{ get; set; }} = {typeValue};"); } builder.AppendLine("\t}"); // class builder.AppendLine("}"); // namespace return(builder.ToString()); }
private static void FlatIndexExplorer() { using var reader = new M2dReader(EXPORTED_PATH); var index = new FlatTypeIndex(reader); Console.WriteLine("Index is ready!"); while (true) { string[] input = (Console.ReadLine() ?? string.Empty).Split(" ", 2); switch (input[0]) { case "quit": return; case "type": case "prop": case "properties": if (input.Length < 2) { Console.WriteLine("Invalid input."); } else { string name = input[1]; FlatType type = index.GetType(name); if (type == null) { Console.WriteLine($"Invalid type: {name}"); continue; } Console.WriteLine(type); foreach (FlatProperty prop in type.GetProperties()) { Console.WriteLine($"{prop.Type,22}{prop.Name,30}: {prop.ValueString()}"); } Console.WriteLine("----------------------Inherited------------------------"); foreach (FlatProperty prop in type.GetInheritedProperties()) { Console.WriteLine($"{prop.Type,22}{prop.Name,30}: {prop.ValueString()}"); } } break; case "sub": case "children": if (input.Length < 2) { Console.WriteLine("Invalid input."); } else { string name = input[1]; FlatType type = index.GetType(name); if (type == null) { Console.WriteLine($"Invalid type: {name}"); continue; } Console.WriteLine(type); foreach (FlatType subType in index.GetSubTypes(name)) { Console.WriteLine($"{subType.Name,30} : {string.Join(',', subType.Mixin.Select(sub => sub.Name))}"); } } break; case "ls": try { bool recursive = input.Contains("-r"); string path = input.FirstOrDefault(arg => arg != "ls" && arg != "-r"); Console.WriteLine(string.Join(", ", index.Hierarchy.List(path, recursive).Select(type => type.Name))); } catch (DirectoryNotFoundException e) { Console.WriteLine(e.Message); } break; case "lsdir": try { string path = input.FirstOrDefault(arg => arg != "lsdir"); Console.WriteLine(string.Join(", ", index.Hierarchy.ListDirectories(path))); } catch (DirectoryNotFoundException e) { Console.WriteLine(e.Message); } break; default: Console.WriteLine($"Unknown command: {string.Join(' ', input)}"); break; } } }