This library provides a way to parse Java .properties files in .NET. This parser is intended for scenarios where you care about non-semantic elements such as comments, whitespace, newlines, and escape sequences. Usage is simple:
using JavaPropertiesParser;
// ...
var document = Parser.Parse(input);Rather than parsing to a dictionary of key/value pairs, this parser gives you an AST that you can query and manipulate as required.
DocumentFixturehas an example of mutating the values in a.propertiesdocument while still preserving formatting and other non-semantic elements.ParserFixturedemonstrates the various.propertiesconstructs that are supported and how they get represented in an AST.
If you want to build a .properties file in memory, consider using the Build class:
using static JavaPropertiesParser.Build;
// ...
Doc(
Pair(
Key("key"),
Separator(":"),
Value("value")
),
Whitespace("\n"),
Pair(
Key("key:2", Encode.Key("key:2")),
Separator("="),
Value("value")
)
);