add draft
This commit is contained in:
38
ResourceString.Net.Logic/Parsers/Resx/Parser.cs
Normal file
38
ResourceString.Net.Logic/Parsers/Resx/Parser.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using ResourceString.Net.Logic.DomainObjects.Resx;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
|
||||
namespace ResourceString.Net.Logic.Parsers.Resx;
|
||||
|
||||
internal static class Parser
|
||||
{
|
||||
public static Option<File> TryParse(string xmlString)
|
||||
{
|
||||
var doc = new XmlDocument();
|
||||
|
||||
try
|
||||
{
|
||||
doc.LoadXml(xmlString);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Option<File>.None;
|
||||
}
|
||||
|
||||
var resources = doc.SelectNodes("descendant::data").OfType<XmlElement>().Select((i, _) =>
|
||||
{
|
||||
var name = i.GetAttribute("name");
|
||||
var type = i.GetAttribute("type");
|
||||
var value = i.SelectSingleNode("descendant::value")?.InnerXml;
|
||||
|
||||
return new Resource(name, value ?? string.Empty)
|
||||
{
|
||||
Type = type
|
||||
};
|
||||
}).ToArray();
|
||||
|
||||
return resources.Any()
|
||||
? Option<File>.Some(new File(resources))
|
||||
: Option<File>.None;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user