DimonSmart.CustomizedDictionary 1.0.1-beta

Prefix Reserved
Suggested Alternatives

DimonSmart.StronglyTypedDictionary

Additional Details

Use new DimonSmart.StronglyTypedDictionary

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

// Install DimonSmart.CustomizedDictionary as a Cake Tool
#tool nuget:?package=DimonSmart.CustomizedDictionary&version=1.0.1-beta&prerelease                

CustomizedDictionary - Strongly Typed Dictionary Generator for .NET

Overview

In modern software development, strongly typed identifiers (IDs) have become increasingly popular, offering an enhanced level of type safety and reducing the risk of misusing IDs of different entities. However, when working with dictionaries that map these IDs to corresponding entities or attributes, developers often face limitations due to the generic "key-value" terminology used by traditional dictionaries. This can lead to confusion, especially when handling multiple dictionaries within the same context, as each dictionary's purpose and the nature of its keys and values become obscured.

CustomizedDictionary aims to bridge this gap by providing a powerful code generation tool that allows developers to define dictionaries with domain-specific naming conventions for both keys and values. This approach not only improves code readability and maintainability but also aligns dictionary usage more closely with the domain model, ensuring a more intuitive development experience.

Features

  • Custom Key and Value Naming: Define dictionaries with meaningful names for keys and values, tailored to your domain model.
  • Seamless Integration: Easily integrate with your .NET projects through NuGet.
  • Pluralization Support: Automatic handling of singular and plural forms for keys and values, enhancing the natural feel of the API.
  • Strong Typing: Enforces type safety, ensuring that keys and values are used correctly throughout your application.

Getting Started

Installation

To get started with CustomizedDictionary, add it to your project via NuGet:

Install-Package CustomizedDictionary

Defining a Custom Dictionary

Create a new file in your project with the extension .dictionary, following the naming convention <Namespace>.<DictionaryName>.dictionary. For example, MyProject.ErrorNumberToMessageMapping.dictionary.

In this file, define your custom dictionary using the format:

Namespace.DictionaryName<KeyType KeyName(KeyNamePlural), ValueType ValueName(ValueNamePlural)>

For example:

MyProject.CustomizedDictionary.ErrorNumberToMessageMapping<int errorCode(ErrorCodes), string message(Messages)>

This definition will be parsed by the CustomizedDictionary code generator to create a strongly typed dictionary class tailored to your specifications.

Usage

Once your custom dictionary is defined, you can use it within your project as follows:

public static void Main()
{
    var errors = new ErrorNumberToMessageMapping();
    errors.Add(404, "Not Found");
    
    if (!errors.ContainsErrorCode(404))
        Console.WriteLine("May be this is not an error at all");

    if (errors.TryGetMessage(404, out var errorMessage))
        Console.WriteLine($"404: {errorMessage}");

    var messageForUndefinedError = errors.GetMessageOrDefault(43, "Unknown Error");
}

Why CustomizedDictionary?

  • Domain-Specific Semantics: Leverage domain-specific terminology for greater clarity and better alignment with business logic.
  • Improved Readability: Enhance code readability with intuitive naming, making it easier to understand and maintain.
  • Type Safety: Benefit from the strong typing system of C#, reducing the risk of errors related to key and value misuse.

Additional Information

While CustomizedDictionary draws inspiration from the concept of strongly typed IDs, it focuses on improving dictionary usage by allowing custom naming for keys and values. This approach shares the ideology of enhancing code clarity and type safety, demonstrating its utility across various applications.

For more detailed documentation, usage examples, and advanced features, please refer to the CustomizedDictionary Documentation.

Embark on a journey towards more expressive, maintainable, and intuitive code with CustomizedDictionary.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.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.

Version Downloads Last updated
1.0.1-beta 209 3/12/2024 1.0.1-beta is deprecated.
1.0.0 245 3/9/2024 1.0.0 is deprecated.