YamlDotNet.Locations
0.2.0
See the version list below for details.
dotnet add package YamlDotNet.Locations --version 0.2.0
NuGet\Install-Package YamlDotNet.Locations -Version 0.2.0
<PackageReference Include="YamlDotNet.Locations" Version="0.2.0" />
paket add YamlDotNet.Locations --version 0.2.0
#r "nuget: YamlDotNet.Locations, 0.2.0"
// Install YamlDotNet.Locations as a Cake Addin #addin nuget:?package=YamlDotNet.Locations&version=0.2.0 // Install YamlDotNet.Locations as a Cake Tool #tool nuget:?package=YamlDotNet.Locations&version=0.2.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(x => "."));
// Output: (3:3)-(7:1)
Console.WriteLine(locator.GetLocation(x => ".Object"));
// Output: (3:10)-(3:19)
Console.WriteLine(locator.GetLocation(x => ".Object.Prop1"));
// Output: (5:5)-(7:1)
Console.WriteLine(locator.GetLocation(x => ".Object.Collection"));
// Output: (6:7)-(6:10)
Console.WriteLine(locator.GetLocation(x => ".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 | Versions 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. |
-
net6.0
- Sprache (>= 2.3.1)
- YamlDotNet (>= 12.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.