add version 0.0.1

This commit is contained in:
2023-02-26 19:03:30 +01:00
parent cedb0bda76
commit 9da07371e9
39 changed files with 2226 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
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 comment = i.SelectSingleNode("descendant::comment")?.InnerXml ?? string.Empty;
var value = i.SelectSingleNode("descendant::value")?.InnerXml ?? string.Empty;
return new Resource(name, value)
{
Type = string.IsNullOrWhiteSpace(type)
? Option<string>.None
: Option<string>.Some(type),
Comment = string.IsNullOrWhiteSpace(comment)
? Option<string>.None
: Option<string>.Some(comment)
};
}).ToArray();
return resources.Any()
? Option<File>.Some(new File(resources))
: Option<File>.None;
}
}