diff --git a/.vscode/launch.json b/.vscode/launch.json
index 4fb1ca1..18ab26c 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -5,7 +5,7 @@
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
- "name": ".NET Core Launch (console)",
+ "name": ".NET Core Launch (WinForms)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
@@ -17,6 +17,19 @@
"console": "internalConsole",
"stopAtEntry": false
},
+ {
+ "name": ".NET Core Launch (console)",
+ "type": "coreclr",
+ "request": "launch",
+ "preLaunchTask": "build",
+ "program": "${workspaceFolder}/Json2CSharpCodeGenerator.Console/bin/Debug/net6.0/win-x64/Json2CSharpCodeGenerator.Console.dll",
+ "args": [
+ "Test_10_SETTINGS_IMMUTABLE_CLASSES_PHARES_INPUT.txt"
+ ],
+ "cwd": "${workspaceFolder}",
+ "stopAtEntry": false,
+ "console": "internalConsole"
+ },
{
"name": ".NET Core Attach",
"type": "coreclr",
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
index b47a147..27c9c6e 100644
--- a/.vscode/tasks.json
+++ b/.vscode/tasks.json
@@ -14,28 +14,16 @@
"problemMatcher": "$msCompile"
},
{
- "label": "publish",
+ "label": "build",
"command": "dotnet",
"type": "process",
"args": [
- "publish",
- "${workspaceFolder}/Json2CSharpCodeGenerator.WinForms/Json2CSharpCodeGenerator.WinForms.csproj",
+ "build",
+ "${workspaceFolder}/Json2CSharpCodeGenerator.Console/Json2CSharpCodeGenerator.Console.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
- },
- {
- "label": "watch",
- "command": "dotnet",
- "type": "process",
- "args": [
- "watch",
- "run",
- "--project",
- "${workspaceFolder}/Json2CSharpCodeGenerator.WinForms/Json2CSharpCodeGenerator.WinForms.csproj"
- ],
- "problemMatcher": "$msCompile"
}
]
}
\ No newline at end of file
diff --git a/Json2CSharpCodeGenerator.Console/Json2CSharpCodeGenerator.Console.csproj b/Json2CSharpCodeGenerator.Console/Json2CSharpCodeGenerator.Console.csproj
new file mode 100644
index 0000000..ab8a32a
--- /dev/null
+++ b/Json2CSharpCodeGenerator.Console/Json2CSharpCodeGenerator.Console.csproj
@@ -0,0 +1,19 @@
+
+
+ enable
+ false
+ 10.0
+ enable
+ Exe
+ win-x64
+ net6.0
+
+
+
+
+
+
+ Always
+
+
+
\ No newline at end of file
diff --git a/Json2CSharpCodeGenerator.Console/Program.cs b/Json2CSharpCodeGenerator.Console/Program.cs
new file mode 100644
index 0000000..0b06586
--- /dev/null
+++ b/Json2CSharpCodeGenerator.Console/Program.cs
@@ -0,0 +1,99 @@
+using Json2CSharpCodeGenerator.Lib;
+using Json2CSharpCodeGenerator.Lib.CodeWriters;
+using System.Text;
+
+namespace Json2CSharpCodeGenerator.Console;
+
+public class Program
+{
+
+ private static void CSharpCodeWriter(List args)
+ {
+ List matches = new();
+ DirectoryInfo directoryInfo;
+ foreach (string arg in args)
+ {
+ if (arg.Length < 3)
+ continue;
+ if (arg[1] == ':' || (arg[0] == '\\' && arg[1] == '\\'))
+ directoryInfo = new(arg);
+ else
+ directoryInfo = new(Path.Combine(AppContext.BaseDirectory, arg));
+ if (!directoryInfo.Root.Exists)
+ continue;
+ if (directoryInfo.Extension is not ".json" and not ".txt")
+ continue;
+ if (directoryInfo.CreationTime < new DateTime(1800, 1, 1))
+ continue;
+ matches.Add(directoryInfo.FullName);
+ }
+ if (!matches.Any())
+ throw new Exception($"Check input <{string.Join(',', args)}>");
+ JsonClassGenerator jsonClassGenerator = new()
+ {
+ AttributeLibrary = JsonLibrary.SystemTextJson,
+ AttributeUsage = JsonPropertyAttributeUsage.OnlyWhenNecessary,
+ CodeWriter = new CSharpCodeWriter(),
+ CollectionType = OutputCollectionType.MutableList,
+ OutputType = OutputTypes.ImmutableClass,
+ UsePascalCase = true,
+ UseThisKeyWord = false,
+ };
+ string input;
+ string outputFile;
+ string errorMessage;
+ string oldOutputFile;
+ StringBuilder stringBuilder;
+ foreach (string match in matches)
+ {
+ outputFile = Path.ChangeExtension(match, ".cs");
+ if (File.Exists(outputFile))
+ {
+ oldOutputFile = Path.ChangeExtension(match, ".old.cs");
+ if (File.Exists(oldOutputFile))
+ File.Delete(oldOutputFile);
+ File.Move(outputFile, oldOutputFile);
+ }
+ input = File.ReadAllText(match);
+ stringBuilder = jsonClassGenerator.GenerateClasses(input, out errorMessage);
+ if (!string.IsNullOrEmpty(errorMessage))
+ throw new Exception(errorMessage);
+ File.WriteAllText(outputFile, stringBuilder.ToString());
+ }
+ }
+
+ public static void Secondary(List args)
+ {
+ int silentIndex = args.IndexOf("s");
+ if (silentIndex > -1)
+ args.RemoveAt(silentIndex);
+ try
+ {
+ CSharpCodeWriter(args);
+ }
+ catch (Exception ex)
+ {
+ System.Console.WriteLine(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
+ }
+ // finally
+ // {
+ // Log.CloseAndFlush();
+ // }
+ if (silentIndex > -1)
+ System.Console.WriteLine("Done. Bye");
+ else
+ {
+ System.Console.WriteLine("Done. Press 'Enter' to end");
+ _ = System.Console.ReadLine();
+ }
+ }
+
+ public static void Main(string[] args)
+ {
+ if (args is not null)
+ Secondary(args.ToList());
+ else
+ Secondary(new List());
+ }
+
+}
\ No newline at end of file
diff --git a/Json2CSharpCodeGenerator.Lib/Json2CSharpCodeGenerator.Lib.csproj b/Json2CSharpCodeGenerator.Lib/Json2CSharpCodeGenerator.Lib.csproj
index 1b459f3..fe8bbad 100644
--- a/Json2CSharpCodeGenerator.Lib/Json2CSharpCodeGenerator.Lib.csproj
+++ b/Json2CSharpCodeGenerator.Lib/Json2CSharpCodeGenerator.Lib.csproj
@@ -6,6 +6,15 @@
win-x64
netstandard2.1
+
+ true
+ 2.1.0.1
+ Infineon Technologies Americas Corp.
+ Mike Phares
+ Infineon.Mesa.Library.Json2CSharpCodeGenerator
+ true
+ snupkg
+
diff --git a/Json2CSharpCodeGenerator.WinForms/Json2CSharpCodeGenerator.WinForms.csproj b/Json2CSharpCodeGenerator.WinForms/Json2CSharpCodeGenerator.WinForms.csproj
index 881f5cd..8e5e3db 100644
--- a/Json2CSharpCodeGenerator.WinForms/Json2CSharpCodeGenerator.WinForms.csproj
+++ b/Json2CSharpCodeGenerator.WinForms/Json2CSharpCodeGenerator.WinForms.csproj
@@ -1,6 +1,7 @@
enable
+ false
10.0
disable
WinExe
diff --git a/Json2CSharpCodeGenerator.sln b/Json2CSharpCodeGenerator.sln
index 0aa0699..13f557a 100644
--- a/Json2CSharpCodeGenerator.sln
+++ b/Json2CSharpCodeGenerator.sln
@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Json2CSharpCodeGenerator.Wi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Json2CSharpCodeGenerator.Tests", "Json2CSharpCodeGenerator.Tests\Json2CSharpCodeGenerator.Tests.csproj", "{81FCF430-5425-48A6-9BE7-745937D78D97}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Json2CSharpCodeGenerator.Console", "Json2CSharpCodeGenerator.Console\Json2CSharpCodeGenerator.Console.csproj", "{CFFB74F0-D227-4F6A-A51A-E44837FFD51B}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -30,5 +32,9 @@ Global
{81FCF430-5425-48A6-9BE7-745937D78D97}.Debug|Any CPU.Build.0 = Debug|Any CPU
{81FCF430-5425-48A6-9BE7-745937D78D97}.Release|Any CPU.ActiveCfg = Release|Any CPU
{81FCF430-5425-48A6-9BE7-745937D78D97}.Release|Any CPU.Build.0 = Release|Any CPU
+ {CFFB74F0-D227-4F6A-A51A-E44837FFD51B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {CFFB74F0-D227-4F6A-A51A-E44837FFD51B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CFFB74F0-D227-4F6A-A51A-E44837FFD51B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {CFFB74F0-D227-4F6A-A51A-E44837FFD51B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal