forked from xoofx/markdig
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkReferenceDefinitionGroup.cs
More file actions
51 lines (43 loc) · 1.73 KB
/
LinkReferenceDefinitionGroup.cs
File metadata and controls
51 lines (43 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// 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.
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using Markdig.Helpers;
namespace Markdig.Syntax;
/// <summary>
/// Contains all the <see cref="LinkReferenceDefinition"/> found in a document.
/// </summary>
/// <seealso cref="ContainerBlock" />
public class LinkReferenceDefinitionGroup : ContainerBlock
{
#if NETFRAMEWORK
private static readonly StringComparer _unicodeIgnoreCaseComparer = StringComparer.InvariantCultureIgnoreCase;
#else
private static readonly StringComparer _unicodeIgnoreCaseComparer = CultureInfo.InvariantCulture.CompareInfo.GetStringComparer(CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace);
#endif
/// <summary>
/// Initializes a new instance of the <see cref="LinkReferenceDefinitionGroup"/> class.
/// </summary>
public LinkReferenceDefinitionGroup() : base(null)
{
Links = new Dictionary<string, LinkReferenceDefinition>(_unicodeIgnoreCaseComparer);
}
/// <summary>
/// Gets an association between a label and the corresponding <see cref="LinkReferenceDefinition"/>
/// </summary>
public Dictionary<string, LinkReferenceDefinition> Links { get; }
public void Set(string label, LinkReferenceDefinition link)
{
if (link is null) ThrowHelper.ArgumentNullException(nameof(link));
if (!Contains(link))
{
Add(link);
Links.TryAdd(label, link);
}
}
public bool TryGet(string label, [NotNullWhen(true)] out LinkReferenceDefinition? link)
{
return Links.TryGetValue(label, out link);
}
}