YamlDotNet.Locations 0.5.0

dotnet add package YamlDotNet.Locations --version 0.5.0
NuGet\Install-Package YamlDotNet.Locations -Version 0.5.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="YamlDotNet.Locations" Version="0.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add YamlDotNet.Locations --version 0.5.0
#r "nuget: YamlDotNet.Locations, 0.5.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.
// Install YamlDotNet.Locations as a Cake Addin
#addin nuget:?package=YamlDotNet.Locations&version=0.5.0

// Install YamlDotNet.Locations as a Cake Tool
#tool nuget:?package=YamlDotNet.Locations&version=0.5.0

YamlDotNet.Locations

An extension of the YamlDotNet library that allows the user to resolve deserialized objects to their position within the source YAML.

User guide

Installation and requirements

Requires .NET 6.0 and YamlDotNet 12.0. Install with nuget:

dotnet add YamlDotNet.Locations

Locating deserialized objects

Using LINQ expressions

LINQ expressions can be used as a typesafe method to query the locations of deserialized values, e.g:

var yaml = @"---
Object:
  Prop1: hello you
  Collection:
    - one
    - two 
"
// MyClass definition omitted for brevity
var (deserialiedValue, locator) = LocatingDeserializer.Deserialize<MyClass>(yaml);

// Output: (2:1)-(7:1)
Console.WriteLine(locator.GetLocation(x => x));
// Output: (3:3)-(7:1)
Console.WriteLine(locator.GetLocation(x => x.Object));
// Output: (3:10)-(3:19)
Console.WriteLine(locator.GetLocation(x => x.Object.Prop1));
// Output: (5:5)-(7:1)
Console.WriteLine(locator.GetLocation(x => x.Object.Collection));
// Output: (6:7)-(6:10)
Console.WriteLine(locator.GetLocation(x => x.Object.Collection[1]));
Using string-based queries

String based LINQ-style query expressions can also be used:

var yaml = @"---
Object:
  Prop1: hello you
  Collection:
    - one
    - two 
";

// MyClass definition omitted for brevity
var (deserialiedValue, locator) = LocatingDeserializer.Deserialize<MyClass>(yaml);

// Output: (2:1)-(7:1)
Console.WriteLine(locator.GetLocation( "."));
// Output: (3:3)-(7:1)
Console.WriteLine(locator.GetLocation( ".Object"));
// Output: (3:10)-(3:19)
Console.WriteLine(locator.GetLocation(".Object.Prop1"));
// Output: (5:5)-(7:1)
Console.WriteLine(locator.GetLocation(".Object.Collection"));
// Output: (6:7)-(6:10)
Console.WriteLine(locator.GetLocation(".Object.Collection[1]"));

A Dire Warning

This library works by exploiting the internal implementation details of YamlDotNet. While it has good test coverage, if these implementation details change in the future, it may stop working correctly.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
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
0.5.0 422 4/27/2023
0.4.0 232 4/18/2023
0.3.1 200 4/13/2023
0.3.0 1,658 9/20/2022
0.2.0 408 9/19/2022
0.1.0 419 9/11/2022