OneCiel.System.Dynamics 0.0.2

dotnet add package OneCiel.System.Dynamics --version 0.0.2
                    
NuGet\Install-Package OneCiel.System.Dynamics -Version 0.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="OneCiel.System.Dynamics" Version="0.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OneCiel.System.Dynamics" Version="0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="OneCiel.System.Dynamics" />
                    
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 OneCiel.System.Dynamics --version 0.0.2
                    
#r "nuget: OneCiel.System.Dynamics, 0.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.
#:package OneCiel.System.Dynamics@0.0.2
                    
#: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=OneCiel.System.Dynamics&version=0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=OneCiel.System.Dynamics&version=0.0.2
                    
Install as a Cake Tool

OneCiel.System.Dynamics

A flexible and dynamic dictionary implementation for .NET Standard 2.1 that provides convenient access to loosely-typed data structures with extensible type resolution.

Installation

dotnet add package OneCiel.System.Dynamics

Features

  • Dynamic Object Access: Access dictionary properties as dynamic members
  • Nested Property Navigation: Support for deep object navigation using dot notation and array indexing
  • Case-Insensitive Keys: All key lookups are performed case-insensitively
  • Type-Safe Value Retrieval: Generic GetValue<T>() method with automatic type conversion
  • Value Resolvers: Extensible resolver pattern for custom type handling and transformation
  • Collection Interfaces: Full implementation of IDictionary<string, object> and related interfaces
  • Deep Cloning: Support for shallow and deep copying of dictionaries
  • Dictionary Merging: Merge multiple dictionaries with flexible control options

Supported Frameworks

  • .NET Standard 2.1
  • .NET 5.0 and later
  • .NET Framework 4.7.2 and later

Core Concepts

IValueResolver

The IValueResolver interface allows you to implement custom type handling and transformation:

public interface IValueResolver
{
    bool CanResolve(object value);
    object Resolve(object value);
}

Register resolvers globally:

DynamicDictionary.RegisterValueResolver(customResolver);

Resolvers are checked in the order they are registered, with the most recently registered resolver checked first.

Quick Usage

Creating a Dictionary

using OneCiel.System.Dynamics;

// Empty dictionary
var dict = new DynamicDictionary();

// From key-value pairs
var dict2 = new DynamicDictionary(new[] 
{
    new KeyValuePair<string, object>("name", "John"),
    new KeyValuePair<string, object>("age", 30)
});

// From existing dictionary
var source = new Dictionary<string, object> { { "key", "value" } };
var dict3 = new DynamicDictionary(source);

Adding and Retrieving Values

dict["name"] = "Alice";
dict["age"] = 25;

var name = dict["name"]; // "Alice"
var age = dict["age"]; // 25

Dynamic Member Access

dynamic person = new DynamicDictionary();
person.firstName = "John";
person.lastName = "Doe";

string fullName = person.firstName + " " + person.lastName;

Nested Property Access

var user = new DynamicDictionary
{
    { "profile", new DynamicDictionary 
    {
        { "address", new DynamicDictionary 
        {
            { "city", "New York" },
            { "country", "USA" }
        }}
    }}
};

// Access nested properties
string city = user["profile.address.city"] as string; // "New York"

// Set nested values (creates intermediate objects)
user["profile.contact.email"] = "user@example.com";

Array Element Access

var data = new DynamicDictionary
{
    { "items", new List<object> { "apple", "banana", "cherry" } },
    { "users", new object[]
    {
        new DynamicDictionary { { "id", 1 }, { "name", "Alice" } },
        new DynamicDictionary { { "id", 2 }, { "name", "Bob" } }
    }}
};

var firstItem = data["items[0]"]; // "apple"
var secondUserName = data["users[1].name"]; // "Bob"

Type-Safe Value Retrieval

var dict = new DynamicDictionary
{
    { "count", "123" },
    { "active", true }
};

// Automatic type conversion with safe fallback
int count = dict.GetValue<int>("count", 0); // 123
bool active = dict.GetValue<bool>("active"); // true
decimal price = dict.GetValue<decimal>("price", 0m); // 0m (not found)

Cloning and Merging

// Shallow copy
var shallowCopy = dict.Clone(deepCopy: false);

// Deep copy
var deepCopy = dict.Clone(deepCopy: true);

// Merge dictionaries
var dict1 = new DynamicDictionary { { "a", 1 }, { "b", 2 } };
var dict2 = new DynamicDictionary { { "b", 3 }, { "c", 4 } };
dict1.Merge(dict2, overwriteExisting: true); // dict1: a=1, b=3, c=4

Custom Value Resolvers

Implement IValueResolver to handle custom types:

public class CustomTypeResolver : IValueResolver
{
    public bool CanResolve(object value)
    {
        return value is MyCustomType;
    }

    public object Resolve(object value)
    {
        var custom = (MyCustomType)value;
        // Transform the value as needed
        return custom.Transform();
    }
}

// Register the resolver
DynamicDictionary.RegisterValueResolver(new CustomTypeResolver());

// Now all DynamicDictionary instances will automatically resolve MyCustomType values

API Reference

Static Methods

Method Description
RegisterValueResolver(IValueResolver) Register a global value resolver
UnregisterValueResolver(IValueResolver) Unregister a resolver
ClearValueResolvers() Remove all registered resolvers
GetRegisteredResolvers() Get read-only list of resolvers

Key Methods

Method Description
Get(string key) Gets value by key or path
GetValue<T>(string key, T defaultValue) Gets typed value with default
Add(string key, object value) Adds or overwrites a key-value pair
Remove(string key) Removes a key
RemoveWhere(Func predicate) Removes items matching condition
Clear() Removes all items
Clone(bool deepCopy) Creates a copy
Merge(DynamicDictionary src, ...) Merges another dictionary
ContainsKey(string key) Checks key existence

License

MIT License

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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 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.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on OneCiel.System.Dynamics:

Package Downloads
OneCiel.System.Dynamics.JsonExtension

JSON serialization and deserialization extensions for OneCiel.System.Dynamics. Provides seamless System.Text.Json integration with DynamicDictionary.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.2 178 11/25/2025
0.0.1 264 11/21/2025

Initial release of OneCiel.System.Dynamics library.