ObjectPath 1.0.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package ObjectPath --version 1.0.2
NuGet\Install-Package ObjectPath -Version 1.0.2
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="ObjectPath" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ObjectPath --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ObjectPath, 1.0.2"
#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 ObjectPath as a Cake Addin #addin nuget:?package=ObjectPath&version=1.0.2 // Install ObjectPath as a Cake Tool #tool nuget:?package=ObjectPath&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ObjectPath
ObjectPath: A simple and intuitive library for accessing object values using string path expressions in .NET.
Installation
Install the ObjectPath library via NuGet:
dotnet add package ObjectPath
Usage
ObjectPath allows you to access values within objects using string path expressions.
Basic Usage
using ObjectPath;
// Example object
var obj = new
{
Name = "John",
Age = 30,
Address = new
{
City = "New York",
Street = "123 Main St"
}
};
// Access values using path expressions
var name = ObjectPath.GetValue(obj, "Name"); // John
var city = ObjectPath.GetValue(obj, "Address.City"); // New York
JSON Example
using System.Text.Json;
using ObjectPath;
// JSON string
var json = @"
{
""name"": ""John"",
""age"": 30,
""address"": {
""city"": ""New York"",
""street"": ""123 Main St""
}
}";
var jsonDocument = JsonDocument.Parse(json);
var jsonElement = jsonDocument.RootElement;
// Access values using path expressions
var name = ObjectPath.GetValue(jsonElement, "name"); // John
var street = ObjectPath.GetValue(jsonElement, "address.street"); // 123 Main St
Array Example
ObjectPath supports accessing array and list elements using index notation.
using ObjectPath;
// Example object with arrays and lists
var obj = new
{
Numbers = new int[] { 1, 2, 3, 4, 5 },
People = new[]
{
new { Name = "John", Age = 30 },
new { Name = "Jane", Age = 25 }
}
};
// Access array elements
var firstNumber = ObjectPath.GetValue(obj, "Numbers[0]"); // 1
var secondPersonName = ObjectPath.GetValue(obj, "People[1].Name"); // Jane
Case Sensitivity
By default, ObjectPath is case-insensitive. You can enable case sensitivity by setting ignoreCase
to false
.
var obj = new
{
Name = "John",
age = 30
};
var name = ObjectPath.GetValue(obj, "Name", ignoreCase: false); // John
var age = ObjectPath.GetValue(obj, "age", ignoreCase: false); // 30
// Throws InvalidObjectPathException
var invalid = ObjectPath.GetValue(obj, "name", ignoreCase: false);
Features
- Access nested properties and fields.
- Supports JSON elements.
- Supports array and list index access.
- Case-insensitive by default, with an option for case sensitivity.
- Handles complex nested structures.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. 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 is compatible. 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 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.