Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This package currently supports:
- **SignalR Extensions** for adding simple SignalR or distributed SignalR backed with Redis.
- **OpenTelemetry**: Metrics, traces, and logs with Prometheus support.
- **Health Checks**: Startup validation and endpoints for monitoring.
- Various **Extensions and Utilities**, including enumerable, string, and queryable extensions.
- Various **Extensions and Utilities**, including enumerable, string, dictionary and queryable extensions.

## Prerequisites

Expand Down Expand Up @@ -613,6 +613,8 @@ This package includes various extensions and utilities to aid development:
- **Enumerable Extensions:** Additional LINQ methods for collections.
- **Host Environment Extensions:** Methods to simplify environment checks (e.g., `IsLocal()`, `IsQa()`).
- **Queryable Extensions:** Extensions for IQueryable, such as conditional `WhereIf`.
- **Dictionary Extensions:** Utility methods for dictionary manipulation in a performant way like `GetOrAdd` and
`TryUpdate`.
- **String Extensions:** Utility methods for string manipulation.
- **Time Zone Extensions:** Methods to handle default time zones within your application. Use `.MapDefaultTimeZone()`,
which
Expand Down
34 changes: 34 additions & 0 deletions src/SharedKernel/Extensions/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace SharedKernel.Extensions;

public static class DictionaryExtensions
{
public static TValue? GetOrAdd<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, TValue? value)
where TKey : notnull
{
ref var val = ref CollectionsMarshal.GetValueRefOrAddDefault(dict, key, out var exists);

if (exists)
{
return val;
}

val = value;
return val;
}

public static bool TryUpdate<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, TValue value)
where TKey : notnull
{
ref var val = ref CollectionsMarshal.GetValueRefOrNullRef(dict, key);
if (Unsafe.IsNullRef(ref val))
{
return false;
}

val = value;
return true;
}
}
4 changes: 2 additions & 2 deletions src/SharedKernel/SharedKernel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Authors>Pandatech</Authors>
<Copyright>MIT</Copyright>
<Version>1.1.1</Version>
<Version>1.1.2</Version>
<PackageId>Pandatech.SharedKernel</PackageId>
<Title>Pandatech Shared Kernel Library</Title>
<PackageTags>Pandatech, shared kernel, library, OpenAPI, Swagger, utilities, scalar</PackageTags>
<Description>Pandatech.SharedKernel provides centralized configurations, utilities, and extensions for ASP.NET Core projects. For more information refere to readme.md document.</Description>
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-sharedkernel</RepositoryUrl>
<PackageReleaseNotes>Added signal r incomming and outgoing message logging</PackageReleaseNotes>
<PackageReleaseNotes>Added dictinory extensions</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down