aboutsummaryrefslogtreecommitdiff
path: root/ErrorResponseCodeGenerator/Program.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-10-27 15:14:03 +0800
committercrupest <crupest@outlook.com>2020-10-27 15:14:03 +0800
commit99a3ef877a406fbde78997dfec0c7a47f3366212 (patch)
tree8b82740de58f51661f5115a164115eda74c5bbb8 /ErrorResponseCodeGenerator/Program.cs
parent4e010b980dad02985cf250bf5b8feb6b4fa385a1 (diff)
downloadtimeline-99a3ef877a406fbde78997dfec0c7a47f3366212.tar.gz
timeline-99a3ef877a406fbde78997dfec0c7a47f3366212.tar.bz2
timeline-99a3ef877a406fbde78997dfec0c7a47f3366212.zip
refactor(back): Rename code generator.
Diffstat (limited to 'ErrorResponseCodeGenerator/Program.cs')
-rw-r--r--ErrorResponseCodeGenerator/Program.cs68
1 files changed, 0 insertions, 68 deletions
diff --git a/ErrorResponseCodeGenerator/Program.cs b/ErrorResponseCodeGenerator/Program.cs
deleted file mode 100644
index 5ea8aaca..00000000
--- a/ErrorResponseCodeGenerator/Program.cs
+++ /dev/null
@@ -1,68 +0,0 @@
-using System;
-using System.Linq;
-using System.Reflection;
-
-namespace ErrorResponseCodeGenerator
-{
- class Program
- {
- static void Main(string[] args)
- {
- var code = "";
-
- void RecursiveAddErrorCode(Type type, bool root)
- {
- code += $@"
- public static class {(root ? "ErrorResponse" : type.Name)}
- {{
-";
-
- foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
- .Where(fi => fi.IsLiteral && !fi.IsInitOnly && fi.FieldType == typeof(int)))
- {
- var path = type.FullName.Replace("+", ".").Replace("Timeline.Models.Http.ErrorCodes.", "") + "." + field.Name;
-
- code += $@"
- public static CommonResponse {field.Name}(params object?[] formatArgs)
- {{
- return new CommonResponse({"ErrorCodes." + path}, string.Format({path.Replace(".", "_")}, formatArgs));
- }}
-
- public static CommonResponse CustomMessage_{field.Name}(string message, params object?[] formatArgs)
- {{
- return new CommonResponse({"ErrorCodes." + path}, string.Format(message, formatArgs));
- }}
-";
- }
-
- foreach (var nestedType in type.GetNestedTypes())
- {
- RecursiveAddErrorCode(nestedType, false);
- }
-
- code += @"
- }
-";
- }
-
- RecursiveAddErrorCode(typeof(Timeline.Models.Http.ErrorCodes), true);
-
- code = @"
-using static Timeline.Resources.Messages;
-
-namespace Timeline.Models.Http
-{
-$
-}
-".Replace("$", code);
-
- Console.WriteLine(code);
-
- TextCopy.Clipboard.SetText(code);
- var oldColor = Console.ForegroundColor;
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Code has copied to clipboard!");
- Console.ForegroundColor = oldColor;
- }
- }
-}