private static string GenerateBdatCollectionFile(BdatCollInfo info) { var sb = new Indenter(); sb.AppendLine("// ReSharper disable InconsistentNaming").AppendLine(); sb.AppendLine("using System;"); sb.AppendLine("using Xb2.Bdat;").AppendLine(); sb.AppendLine("namespace Xb2.Types"); sb.AppendLineAndIncrease("{"); sb.AppendLine("[Serializable]"); sb.AppendLine("public class BdatCollection"); sb.AppendLineAndIncrease("{"); foreach (var type in info.Types) { foreach (string table in type.TableNames.OrderBy(x => x)) { sb.AppendLine($"public BdatTable<{type.Name}> {table};"); } } sb.DecreaseAndAppendLine("}"); sb.DecreaseAndAppendLine("}"); return(sb.ToString()); }
private static string GenerateReadFunctionsFile(BdatCollInfo info) { var sb = new Indenter(); sb.AppendLine("// ReSharper disable InconsistentNaming").AppendLine(); sb.AppendLine("using System;"); sb.AppendLine("using Xb2.Types;").AppendLine(); sb.AppendLine("namespace Xb2.Serialization"); sb.AppendLineAndIncrease("{"); sb.AppendLine("public static class ReadFunctions"); sb.AppendLineAndIncrease("{"); bool firstFunction = true; foreach (var type in info.Types) { if (!firstFunction) { sb.AppendLine(); } firstFunction = false; GenerateReadFunction(type, sb); } sb.AppendLine(); GenerateSetReferencesFunction(sb, info); sb.DecreaseAndAppendLine("}"); sb.DecreaseAndAppendLine("}"); return(sb.ToString()); }
private static string GenerateTypeMapFile(BdatCollInfo info) { var sb = new StringBuilder(); foreach (var type in info.Types) { sb.Append(type.Name); foreach (var table in type.TableNames.OrderBy(x => x)) { sb.Append($",{table}"); } sb.AppendLine(); } return(sb.ToString()); }
public static void CreateFiles(BdatTable[] tables, string csDir) { Directory.CreateDirectory(csDir); var info = new BdatCollInfo(tables); string bdatTypes = GenerateTypesFile(info); string readFunctions = GenerateReadFunctionsFile(info); string bdatCollection = GenerateBdatCollectionFile(info); string typeMap = GenerateTypeMapFile(info); File.WriteAllText(Path.Combine(csDir, "BdatTypes.cs"), bdatTypes); File.WriteAllText(Path.Combine(csDir, "ReadFunctions.cs"), readFunctions); File.WriteAllText(Path.Combine(csDir, "BdatCollection.cs"), bdatCollection); File.WriteAllText(Path.Combine(csDir, "TypeMap.txt"), typeMap); }
private static void GenerateSetReferencesFunction(Indenter sb, BdatCollInfo info) { sb.AppendLine("public static void SetReferences(BdatCollection tables)"); sb.AppendLineAndIncrease("{"); bool firstTable = true; foreach (var table in info.Tables) { if (!firstTable) { sb.AppendLine(); } firstTable = false; GenerateSetReferencesTable(sb, table); } sb.DecreaseAndAppendLine("}"); }
private static string GenerateTypesFile(BdatCollInfo info) { var sb = new Indenter(); sb.AppendLine("// ReSharper disable InconsistentNaming"); sb.AppendLine(); sb.AppendLine("using System;"); sb.AppendLine(); sb.AppendLine("namespace Xb2.Types"); sb.AppendLineAndIncrease("{"); for (int i = 0; i < info.Types.Length; i++) { if (i != 0) { sb.AppendLine(); } GenerateType(info.Types[i], sb); } sb.DecreaseAndAppendLine("}"); return(sb.ToString()); }