DanielWillett.JavaPropertiesParser 1.1.0

dotnet add package DanielWillett.JavaPropertiesParser --version 1.1.0
                    
NuGet\Install-Package DanielWillett.JavaPropertiesParser -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DanielWillett.JavaPropertiesParser" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DanielWillett.JavaPropertiesParser" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="DanielWillett.JavaPropertiesParser" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DanielWillett.JavaPropertiesParser --version 1.1.0
                    
#r "nuget: DanielWillett.JavaPropertiesParser, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=DanielWillett.JavaPropertiesParser&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=DanielWillett.JavaPropertiesParser&version=1.1.0
                    
Install as a Cake Tool

JavaPropertiesParser

Parses and writes Java Properties data.

Installation

Install the latest release of the package from NuGet.

Features

  • Fully conforms to the "spec".
  • Supports escape sequences (\n, \r, \t, \\, \u0D9E).
  • Supports multi-line values by ending a line with a backslash.
  • Can parse comments and empty lines if needed.
  • Configurable options (see PropertiesReaderOptions).
  • Support the following property separators (:, =, whitespace).
  • Opt-in support for using / and // as comment characters.
    • Must set RecognizeSlashComments = true on the reader.
  • Well tested

Examples

Writing - Write a few pairs of data

using StringWriter stringWriter = new StringWriter();
using (PropertiesWriter writer = new PropertiesWriter(stringWriter))
{
    writer.Separator = '=';

    writer.WriteKey("JustASingleKey");
    writer.WriteKeyValue("Key", "Value");

    writer.WriteLine();

    writer.WriteComment("Animals");
    writer.WriteKeyValue("Dog", "Land");
    writer.WriteKeyValue("Cat", "Land");
    writer.WriteKeyValue("Fish", "Water");

    writer.WriteLine();
    writer.WriteLine();

    writer.WriteComment(
        "The following states are important for some reason",
        PropertiesCommentType.ExclamationWrapped
    );
    writer.WriteKey("States");
    string[] states = [ "NC", "GA", "NY", "AK", "CA", "HI", "TX" ];
    for (int i = 0; i < states.Length; ++i)
    {
        writer.WriteValue(i == states.Length - 1 ? states[i] : $"{states[i]}, ");
    }
}

Console.WriteLine(stringWriter.ToString());

Output:

JustASingleKey
Key = Value

# Animals
Dog = Land
Cat = Land
Fish = Water


! The following states are important for some reason !
States = NC, \
         GA, \
         NY, \
         AK, \
         CA, \
         HI, \
         TX

Reading - Loop through all keys and values

string filePath = "./file.txt";
using PropertiesReader reader = new PropertiesReader(filePath);

while (reader.TryReadPair(out string key, out string value, skipKeysWithNoValue: true))
{
    Console.WriteLine($"{key} = {value}");
}

Output (using file.txt):

> Property1 = Value1
  Property3 = Value2

Reading - Print all comments

const string content = """
                       ! This represents the time at which you will go to sleep tonight
                       Time: 4:30 AM
                              
                       # This feature only works on Windows.
                       OS: Windows
                              
                       # Comments can also be 'wrapped' like this #
                       """;

using PropertiesReader reader = new PropertiesReader(new StringReader(content), disposeReaderOnDispose: true);

while (reader.TryRead())
{
    if (reader.TokenType == PropertiesTokenType.Comment)
        Console.WriteLine($"{reader.CommentType, -16} \"{reader.Value}\"");
}

Output:

> Exclamation      "This represents the time at which you will go to sleep tonight"
  Hashtag          "This feature only works on Windows."
  HashtagWrapped   "Comments can also be 'wrapped' like this"
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.0 is compatible.  netstandard1.1 was computed.  netstandard1.2 was computed.  netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 is compatible. 
.NET Framework net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Windows Phone wp8 was computed.  wp81 was computed.  wpa81 was computed. 
Windows Store netcore was computed.  netcore45 was computed.  netcore451 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DanielWillett.JavaPropertiesParser:

Package Downloads
Uncreated.Warfare

Main framework for the Uncreated Warfare Military Simulation server based off of the military game Squad.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 264 17 days ago
1.0.0 1,654 4/5/2024 1.0.0 is deprecated because it has critical bugs.

Fixed some inconsistancies with the file standard and added support for whitespace separators.