commit
389781592e
1 changed files with 23 additions and 11 deletions
|
@ -1,7 +1,9 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Resources;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
||||
|
@ -26,26 +28,37 @@ namespace Microsoft.DotNet.Tools.Resgen
|
|||
|
||||
app.OnExecute(() =>
|
||||
{
|
||||
WriteResourcesFile(inputFile.Value, outputFile.Value);
|
||||
WriteResourcesFileIfNotEmpty(inputFile.Value, outputFile.Value);
|
||||
return 0;
|
||||
});
|
||||
|
||||
return app.Execute(args);
|
||||
}
|
||||
|
||||
private static void WriteResourcesFile(string resxFilePath, string outputFile)
|
||||
private static void WriteResourcesFileIfNotEmpty(string resxFilePath, string outputFile)
|
||||
{
|
||||
using (var fs = File.OpenRead(resxFilePath))
|
||||
using (var outfs = File.Create(outputFile))
|
||||
{
|
||||
var document = XDocument.Load(fs);
|
||||
|
||||
var data = document.Root.Elements("data");
|
||||
|
||||
if (data.Any())
|
||||
{
|
||||
WriteResourcesFile(outfs, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteResourcesFile(Stream outfs, IEnumerable<XElement> data)
|
||||
{
|
||||
var rw = new ResourceWriter(outfs);
|
||||
|
||||
foreach (var e in document.Root.Elements("data"))
|
||||
foreach (var e in data)
|
||||
{
|
||||
string name = e.Attribute("name").Value;
|
||||
string value = e.Element("value").Value;
|
||||
var name = e.Attribute("name").Value;
|
||||
var value = e.Element("value").Value;
|
||||
|
||||
rw.AddResource(name, value);
|
||||
}
|
||||
|
@ -53,5 +66,4 @@ namespace Microsoft.DotNet.Tools.Resgen
|
|||
rw.Generate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue