Exploring CollectionsMarshal for Dictionary

 
 
  • Gérald Barré
Unlike ConcurrentDictionary, Dictionary does not have a GetOrAdd method. This method is useful when you want to add a key-value pair to the dictionary if the key does not exist, or return the value if the key already exists. The naive implementation of this method looks like this: public static TValue GetOrAdd<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, TValue value) where TKey : notnull {… [read more]

Signing commits in Git using SSH keys on Windows

 
 
  • Gérald Barré
Signing commits in Git is a way to verify the authenticity and integrity of your commits. This ensures that the commits are indeed made by you and have not been tampered with. On Windows, it's easy to set up SSH-Agent for easy signature. Here's how you can do it. First, you need to install SSH on Windows. Open a PowerShell window as an administrator and run the following command to install the OpenSSH… [read more]

Using the binary log to find the source of a .NET dependency

 
 
  • Gérald Barré
Understanding where a dependency comes from can be tedious. This is especially true when you have a large project with many dependencies. Recently, .NET brings a new tool dotnet nuget why to help you understand why a package is installed in your project. However, there is a better way to do it, and it doesn't requires a recent SDK. dotnet nuget why can explain why a package is included in your project:… [read more]

NuGet Packages: security risks and best practices

 
 
  • Gérald Barré
NuGet packages offer a convenient way to share code, but many developers download them without reviewing the contents or verifying updates when new versions are released. When you install a NuGet package, you are: Downloading code from unknown authors that has likely not been thoroughly reviewed by others Running it with full permissions on your local machine, potentially exposing your personal data… [read more]

Embedded Languages Supported by Roslyn

 
 
  • Gérald Barré
In a recent post, I shared how to highlight C# code in string values. Roslyn provides more built-in highlighters / code-completions in string values. Most of the supported languages are available as constants of the StringSyntaxAttribute class. To indicate the language, you can use the lang or language comment or the [StringSyntax] attribute. The languages mentioned in this post are handled by Roslyn (VS,… [read more]