Change to IncludeSymbols
and Added Json2CSharpCodeGenerator.Console
This commit is contained in:
parent
8dfc8fe9b8
commit
8b36f3d30a
15
.vscode/launch.json
vendored
15
.vscode/launch.json
vendored
@ -5,7 +5,7 @@
|
|||||||
// Use IntelliSense to find out which attributes exist for C# debugging
|
// Use IntelliSense to find out which attributes exist for C# debugging
|
||||||
// Use hover for the description of the existing attributes
|
// Use hover for the description of the existing attributes
|
||||||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
// 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",
|
"type": "coreclr",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"preLaunchTask": "build",
|
"preLaunchTask": "build",
|
||||||
@ -17,6 +17,19 @@
|
|||||||
"console": "internalConsole",
|
"console": "internalConsole",
|
||||||
"stopAtEntry": false
|
"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",
|
"name": ".NET Core Attach",
|
||||||
"type": "coreclr",
|
"type": "coreclr",
|
||||||
|
18
.vscode/tasks.json
vendored
18
.vscode/tasks.json
vendored
@ -14,28 +14,16 @@
|
|||||||
"problemMatcher": "$msCompile"
|
"problemMatcher": "$msCompile"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "publish",
|
"label": "build",
|
||||||
"command": "dotnet",
|
"command": "dotnet",
|
||||||
"type": "process",
|
"type": "process",
|
||||||
"args": [
|
"args": [
|
||||||
"publish",
|
"build",
|
||||||
"${workspaceFolder}/Json2CSharpCodeGenerator.WinForms/Json2CSharpCodeGenerator.WinForms.csproj",
|
"${workspaceFolder}/Json2CSharpCodeGenerator.Console/Json2CSharpCodeGenerator.Console.csproj",
|
||||||
"/property:GenerateFullPaths=true",
|
"/property:GenerateFullPaths=true",
|
||||||
"/consoleloggerparameters:NoSummary"
|
"/consoleloggerparameters:NoSummary"
|
||||||
],
|
],
|
||||||
"problemMatcher": "$msCompile"
|
"problemMatcher": "$msCompile"
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "watch",
|
|
||||||
"command": "dotnet",
|
|
||||||
"type": "process",
|
|
||||||
"args": [
|
|
||||||
"watch",
|
|
||||||
"run",
|
|
||||||
"--project",
|
|
||||||
"${workspaceFolder}/Json2CSharpCodeGenerator.WinForms/Json2CSharpCodeGenerator.WinForms.csproj"
|
|
||||||
],
|
|
||||||
"problemMatcher": "$msCompile"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<PropertyGroup>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
<LangVersion>10.0</LangVersion>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Infineon.Mesa.Library.Json2CSharpCodeGenerator" Version="2.1.0.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\Json2CSharpCodeGenerator.Tests\Test_10_SETTINGS_IMMUTABLE_CLASSES_PHARES_INPUT.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
99
Json2CSharpCodeGenerator.Console/Program.cs
Normal file
99
Json2CSharpCodeGenerator.Console/Program.cs
Normal file
@ -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<string> args)
|
||||||
|
{
|
||||||
|
List<string> 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<string> 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<string>());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,6 +6,15 @@
|
|||||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
<TargetFramework>netstandard2.1</TargetFramework>
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
|
<Version>2.1.0.1</Version>
|
||||||
|
<Company>Infineon Technologies Americas Corp.</Company>
|
||||||
|
<Authors>Mike Phares</Authors>
|
||||||
|
<PackageId>Infineon.Mesa.Library.Json2CSharpCodeGenerator</PackageId>
|
||||||
|
<IncludeSymbols>true</IncludeSymbols>
|
||||||
|
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||||
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CG.Pluralization" Version="0.3000.12" />
|
<PackageReference Include="CG.Pluralization" Version="0.3000.12" />
|
||||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
<LangVersion>10.0</LangVersion>
|
<LangVersion>10.0</LangVersion>
|
||||||
<Nullable>disable</Nullable>
|
<Nullable>disable</Nullable>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
|
@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Json2CSharpCodeGenerator.Wi
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Json2CSharpCodeGenerator.Tests", "Json2CSharpCodeGenerator.Tests\Json2CSharpCodeGenerator.Tests.csproj", "{81FCF430-5425-48A6-9BE7-745937D78D97}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Json2CSharpCodeGenerator.Tests", "Json2CSharpCodeGenerator.Tests\Json2CSharpCodeGenerator.Tests.csproj", "{81FCF430-5425-48A6-9BE7-745937D78D97}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Json2CSharpCodeGenerator.Console", "Json2CSharpCodeGenerator.Console\Json2CSharpCodeGenerator.Console.csproj", "{CFFB74F0-D227-4F6A-A51A-E44837FFD51B}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{81FCF430-5425-48A6-9BE7-745937D78D97}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
Loading…
x
Reference in New Issue
Block a user