Skip to content

An extension method to provide GetOrAdd as found in ConcurrentDictionary to every IDictionary type. A part of the C# Language Syntactic Sugar suite.

License

Notifications You must be signed in to change notification settings

tonygiang/CLSS.ExtensionMethods.IDictionary.GetOrAdd

Repository files navigation

CLSS.ExtensionMethods.IDictionary.GetOrAdd

Problem

GetOrAdd is a convenient method for ConcurrentDictionary but not for other IDictionary types in the standard class library. This method is often used to cache results of pure functions, ie functions that always yield a deterministic result for each argument.

Solution

This package provides GetOrAdd method to all IDictionary types.

Example:

using CLSS;

var NumberSpellings = new Dictionary<int, string>();
Func<int, string> NumberToSpelling = n => { /* Implementation */ };
var spelling_285 = NumberSpellings.GetOrAdd(285, NumberToSpelling);
This package is a part of the C# Language Syntactic Sugar suite.

About

An extension method to provide GetOrAdd as found in ConcurrentDictionary to every IDictionary type. A part of the C# Language Syntactic Sugar suite.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages