Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up generated Fields.cs/FieldTags.cs files #922

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions DDTool/DDTool/Generators/GenFieldTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,18 @@ private static string Generate(List<DDField> fields) {
{
"// This is a generated file. Don't edit it directly!",
"",
"using System;",
"namespace QuickFix.Fields;",
"",
"namespace QuickFix.Fields",
"{",
" /// <summary>",
" /// FIX Field Tag Values",
" /// </summary>",
" public static class Tags",
" {"
"/// <summary>",
"/// FIX Field Tag Values",
"/// </summary>",
"public static class Tags",
"{"
};

foreach (var fld in fields)
lines.Add($" public const int {fld.Name} = {fld.Tag};");
lines.Add($" public const int {fld.Name} = {fld.Tag};");

lines.Add(" }");
lines.Add("}");
lines.Add("");

Expand Down
69 changes: 34 additions & 35 deletions DDTool/DDTool/Generators/GenFields.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using DDTool.Structures;

Expand Down Expand Up @@ -29,11 +30,11 @@ private static string Generate(List<DDField> fields) {
"",
"using System;",
"",
"namespace QuickFix.Fields",
"{"
"namespace QuickFix.Fields;",
};

foreach (var field in fields) {
lines.Add("");
switch (field.CsClass) {
case "DateTimeField":
case "TimeOnlyField":
Expand All @@ -45,56 +46,54 @@ private static string Generate(List<DDField> fields) {
}
}

lines.Add("}");
lines.Add("");
return string.Join(Environment.NewLine, lines);
}

private static void AppendDateField(List<string> lines, DDField field) {
lines.Add(" /// <summary>");
lines.Add($" /// {field.Name} Field");
lines.Add(" /// </summary>");
lines.Add($" public sealed class {field.Name} : {field.CsClass}");
lines.Add(" {");
lines.Add($" public const int TAG = {field.Tag};");
lines.Add("/// <summary>");
lines.Add($"/// {field.Name} Field");
lines.Add("/// </summary>");
lines.Add($"public sealed class {field.Name} : {field.CsClass}");
lines.Add("{");
lines.Add($" public const int TAG = {field.Tag};");
lines.Add("");

lines.Add($" public {field.Name}()");
lines.Add($" :base(Tags.{field.Name}) {{}}");
lines.Add($" public {field.Name}({field.BaseType} val)");
lines.Add($" :base(Tags.{field.Name}, val) {{}}");
lines.Add($" public {field.Name}({field.BaseType} val, bool showMilliseconds)");
lines.Add($" :base(Tags.{field.Name}, val, showMilliseconds) {{}}");
lines.Add($" public {field.Name}({field.BaseType} val, Converters.TimeStampPrecision precision)");
lines.Add($" :base(Tags.{field.Name}, val, precision) {{}}");
lines.Add($" public {field.Name}()");
lines.Add($" : base(Tags.{field.Name}) {{}}");
lines.Add($" public {field.Name}({field.BaseType} val)");
lines.Add($" : base(Tags.{field.Name}, val) {{}}");
lines.Add($" public {field.Name}({field.BaseType} val, bool showMilliseconds)");
lines.Add($" : base(Tags.{field.Name}, val, showMilliseconds) {{}}");
lines.Add($" public {field.Name}({field.BaseType} val, Converters.TimeStampPrecision precision)");
lines.Add($" : base(Tags.{field.Name}, val, precision) {{}}");
lines.Add("");

AppendFieldEnumerations(lines, field);

lines.Add(" }");
lines.Add("");
lines.Add("}");
lines.Add("");
}

private static void AppendNonDateField(List<string> lines, DDField field) {
lines.Add(" /// <summary>");
lines.Add($" /// {field.Name} Field");
lines.Add(" /// </summary>");
lines.Add($" public sealed class {field.Name} : {field.CsClass}");
lines.Add(" {");
lines.Add($" public const int TAG = {field.Tag};");
lines.Add("/// <summary>");
lines.Add($"/// {field.Name} Field");
lines.Add("/// </summary>");
lines.Add($"public sealed class {field.Name} : {field.CsClass}");
lines.Add("{");
lines.Add($" public const int TAG = {field.Tag};");
lines.Add("");

lines.Add($" public {field.Name}()");
lines.Add($" :base(Tags.{field.Name}) {{}}");
lines.Add($" public {field.Name}({field.BaseType} val)");
lines.Add($" :base(Tags.{field.Name}, val) {{}}");
lines.Add("");
lines.Add($" public {field.Name}()");
lines.Add($" : base(Tags.{field.Name}) {{}}");
lines.Add($" public {field.Name}({field.BaseType} val)");
lines.Add($" : base(Tags.{field.Name}, val) {{}}");

AppendFieldEnumerations(lines, field);
if (lines.Count > 0) {
AppendFieldEnumerations(lines, field);
}

lines.Add(" }");
lines.Add("");
lines.Add("}");
lines.Add("");
}

Expand All @@ -103,7 +102,7 @@ private static void AppendFieldEnumerations(List<string> lines, DDField field) {
return;

lines.Add("");
lines.Add(" // Field Enumerations");
lines.Add(" // Field Enumerations");

foreach (var enumVal in field.Enums) {
string desc = enumVal.Desc.Replace('.', '_');
Expand All @@ -122,7 +121,7 @@ private static void AppendFieldEnumerations(List<string> lines, DDField field) {
$"unsupported field type '{field.BaseType}' ({field})")
};

lines.Add($" public const {field.BaseType} {desc} = {outVal};");
lines.Add($" public const {field.BaseType} {desc} = {outVal};");
}
}
}
Loading
Loading