ToolBX.FileGuy.Newtonsoft 3.0.0

dotnet add package ToolBX.FileGuy.Newtonsoft --version 3.0.0
                    
NuGet\Install-Package ToolBX.FileGuy.Newtonsoft -Version 3.0.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="ToolBX.FileGuy.Newtonsoft" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ToolBX.FileGuy.Newtonsoft" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ToolBX.FileGuy.Newtonsoft" />
                    
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 ToolBX.FileGuy.Newtonsoft --version 3.0.0
                    
#r "nuget: ToolBX.FileGuy.Newtonsoft, 3.0.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.
#:package ToolBX.FileGuy.Newtonsoft@3.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ToolBX.FileGuy.Newtonsoft&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ToolBX.FileGuy.Newtonsoft&version=3.0.0
                    
Install as a Cake Tool

FileGuy

FileGuy.Json

FileGuy.Json is a simple library that allows you to read and write json to and from files in a simple way using the Newtonsoft.Json library.

FileSerializer

A service that allows you to read and write json to and from files directly.

Usage

private readonly FileSerializer _fileSerializer;

public MyClass(FileSerializer fileSerializer)
{
	_fileSerializer = fileSerializer;
}

public void WriteJsonToFile()
{
	var myObject = new MyObject();
	_fileSerializer.Serialize(myObject, "myObject.json");
}

A FileSerializerOptions object can also be passed which contains a Newtonstoft.Json.JsonSerializerSettings object. This allows you to configure the serialization process.

var options = new FileSerializerOptions
{
	Serializer = new JsonSerializerSettings
	{
		PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
		WriteIndented = true
	}
};

_fileSerializer.Serialize(myObject, "myObject.json", options);

The Deserialize method works as you would expect.

private readonly FileSerializer _fileSerializer;

public MyClass(FileSerializer fileSerializer)
{
	_fileSerializer = fileSerializer;
}

public void ReadJsonFromFile()
{
	var myObject = _fileSerializer.Deserialize<MyObject>("myObject.json", new FileSerializerOptions
	{
		Serializer = new JsonSerializerSettings
		{
			PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
			WriteIndented = true
		}
	});
}

Compression/Decompression

The FileSerializer class also has methods for compressing and decompressing json files in the same way that FileGuy.FileSaver and FileGuy.FileLoader already do.

private readonly FileSerializer _fileSerializer;

public MyClass(FileSerializer fileSerializer)
{
	_fileSerializer = fileSerializer;
}

public void CompressJsonFile()
{
	_fileSerializer.Serialize("myObject.json", new FileSerializerOptions
	{
		//Uses NoCompression by default
		CompressionLevel = CompressionLevel.Optimal
	});
}

public void DecompressJsonFile()
{
	var myObject = _fileSerializer.Decompress<MyObject>("myObject.json");
	...
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 162 9/27/2024
3.0.0-beta1 102 9/23/2024
2.2.0 186 1/13/2024
2.2.0-beta2 105 1/11/2024
2.2.0-beta1 165 1/7/2024
2.0.2 266 6/19/2023
2.0.1 297 4/27/2023
2.0.0 424 11/12/2022
2.0.0-beta1 227 10/7/2022
1.0.1 455 10/7/2022
1.0.0 490 5/16/2022