Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 1 addition & 4 deletions src/Markdig/Helpers/CharacterMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ public CharacterMap(IEnumerable<KeyValuePair<char, T>> maps)
{
nonAsciiMap ??= [];

if (!nonAsciiMap.ContainsKey(openingChar))
{
nonAsciiMap[openingChar] = state.Value;
}
nonAsciiMap.TryAdd(openingChar, state.Value);
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/Markdig/Parsers/ParserList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ protected ParserList(IEnumerable<T> parsersArg) : base(parsersArg)
{
foreach (var openingChar in parser.OpeningCharacters)
{
if (!charCounter.ContainsKey(openingChar))
{
charCounter[openingChar] = 0;
}
charCounter.TryAdd(openingChar, 0);
charCounter[openingChar]++;
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/Markdig/Polyfills/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// This file is licensed under the BSD-Clause 2 license.
// See the license.txt file in the project root for more information.

#if !(NETSTANDARD2_1_OR_GREATER || NET)

namespace System.Collections.Generic;

internal static class DictionaryExtensions
{
public static bool TryAdd<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value) where TKey : notnull
{
if (!dictionary.ContainsKey(key))
{
dictionary[key] = value;
return true;
}

return false;
}
}

#endif
5 changes: 1 addition & 4 deletions src/Markdig/Syntax/LinkReferenceDefinitionGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ public void Set(string label, LinkReferenceDefinition link)
if (!Contains(link))
{
Add(link);
if (!Links.ContainsKey(label))
{
Links[label] = link;
}
Links.TryAdd(label, link);
}
}

Expand Down