From 1cb6730bb11cff336aeb7e6c95e2884fbe6f0e7a Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Wed, 18 May 2022 22:03:08 -0500 Subject: [PATCH] Switched Generation command to use lambda handler. --- DotNetResxUtils/Commands/GenerationCommand.cs | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/DotNetResxUtils/Commands/GenerationCommand.cs b/DotNetResxUtils/Commands/GenerationCommand.cs index 0ddec8f..69034c6 100644 --- a/DotNetResxUtils/Commands/GenerationCommand.cs +++ b/DotNetResxUtils/Commands/GenerationCommand.cs @@ -7,37 +7,34 @@ using System.Resources.NetStandard; namespace DotNetResxUtils.Commands { - internal class GenerationCommand : Command + internal class GenerationCommand : Command { const string NAME = "generate"; const string DESC = "Generate a .resx file."; public GenerationCommand() : base(NAME, DESC) { + Argument destArg = new Argument("destination", "The destination path to store this file. If no extension is given, .resx will automatically be concatenated."); + Add(destArg); Option fromOpt = new Option("--from", "Generates a .resx file from the given file."); + Add(fromOpt); - Argument destArg = new Argument("destination", "The destination path to store this file. If no extension is given, .resx will automatically be concatenated."); - - this.AddOption(fromOpt); - this.AddArgument(destArg); - - this.SetHandler(CommandHandler, destArg, fromOpt); - } - private async void CommandHandler(FileInfo to, FileInfo? from) - { - IDictionary flattened = new Dictionary(); - if (from != null) + this.SetHandler(async (FileInfo to, FileInfo? from) => { - flattened = await FlattenJson(from); - } - using (ResXResourceWriter resxWriter = new ResXResourceWriter(to.FullName)) - { - foreach (KeyValuePair keyVal in flattened) + IDictionary flattened = new Dictionary(); + if (from != null) { - resxWriter.AddResource(keyVal.Key, keyVal.Value); + flattened = await FlattenJson(from); } - } + using (ResXResourceWriter resxWriter = new ResXResourceWriter(to.FullName)) + { + foreach (KeyValuePair keyVal in flattened) + { + resxWriter.AddResource(keyVal.Key, keyVal.Value); + } + } + }, destArg, fromOpt); } private async Task> FlattenJson(FileInfo jsonFile)