Skip to content

Commit 38094e7

Browse files
committed
docs: 为双向字典添加英文文档注释
添加英文文档注释以支持国际化,提升代码的可读性和可维护性。
1 parent 209d68a commit 38094e7

1 file changed

Lines changed: 52 additions & 36 deletions

File tree

GameFrameX.Foundation.Extensions/BidirectionalDictionary.cs

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,34 @@ namespace GameFrameX.Foundation.Extensions;
3737
/// 双向字典,实现键和值的双向映射。支持在两个方向上进行快速查找。
3838
/// 注意:键和值都必须是唯一的,不允许重复。
3939
/// </summary>
40-
/// <typeparam name="TKey">键的类型。必须是可以作为字典键的类型。</typeparam>
41-
/// <typeparam name="TValue">值的类型。必须是可以作为字典键的类型。</typeparam>
40+
/// <remarks>
41+
/// A bidirectional dictionary that implements bidirectional mapping between keys and values.
42+
/// Supports fast lookup in both directions.
43+
/// Note: Both keys and values must be unique, duplicates are not allowed.
44+
/// </remarks>
45+
/// <typeparam name="TKey">键的类型,必须是可以作为字典键的类型 / The type of keys, must be a valid dictionary key type.</typeparam>
46+
/// <typeparam name="TValue">值的类型,必须是可以作为字典键的类型 / The type of values, must be a valid dictionary key type.</typeparam>
4247
public class BidirectionalDictionary<TKey, TValue>
4348
{
44-
/// <summary>
45-
/// 存储键到值的映射关系
49+
/// <summary>
50+
/// 存储键到值的映射关系
4651
/// </summary>
4752
private readonly Dictionary<TKey, TValue> _forwardDictionary;
4853

49-
/// <summary>
50-
/// 存储值到键的映射关系
54+
/// <summary>
55+
/// 存储值到键的映射关系
5156
/// </summary>
5257
private readonly Dictionary<TValue, TKey> _reverseDictionary;
5358

5459
/// <summary>
5560
/// 初始化 <see cref="BidirectionalDictionary{TKey, TValue}" /> 类的新实例。
5661
/// </summary>
57-
/// <param name="initialCapacity">初始容量,用于预分配内部字典的空间。默认值为8,必须大于等于0。</param>
58-
/// <exception cref="ArgumentOutOfRangeException">当 <paramref name="initialCapacity"/> 小于0时抛出</exception>
5962
/// <remarks>
60-
/// 合理设置初始容量可以避免频繁的内部扩容操作,提高性能。
63+
/// Initializes a new instance of the <see cref="BidirectionalDictionary{TKey, TValue}" /> class.
64+
/// Setting a reasonable initial capacity can avoid frequent internal expansion and improve performance.
6165
/// </remarks>
66+
/// <param name="initialCapacity">初始容量,用于预分配内部字典的空间,默认值为 8,必须大于等于 0 / The initial capacity used to pre-allocate space for the internal dictionaries, defaults to 8, must be greater than or equal to 0.</param>
67+
/// <exception cref="ArgumentOutOfRangeException">当 <paramref name="initialCapacity"/> 小于 0 时抛出 / Thrown when <paramref name="initialCapacity"/> is less than 0.</exception>
6268
public BidirectionalDictionary(int initialCapacity = 8)
6369
{
6470
ArgumentOutOfRangeException.ThrowIfNegative(initialCapacity, nameof(initialCapacity));
@@ -69,13 +75,14 @@ public BidirectionalDictionary(int initialCapacity = 8)
6975
/// <summary>
7076
/// 尝试根据值获取对应的键。
7177
/// </summary>
72-
/// <param name="value">要查找的值,不能为 null(如果 TValue 是引用类型)。</param>
73-
/// <param name="key">查找到的键。如果未找到对应的键,将设置为默认值。</param>
74-
/// <returns>如果成功找到键,则为 true;否则为 false。</returns>
75-
/// <exception cref="ArgumentNullException">当 <paramref name="value"/> 为 null 且 TValue 是引用类型时抛出</exception>
7678
/// <remarks>
77-
/// 此操作的时间复杂度为 O(1)。
79+
/// Tries to get the key associated with the specified value.
80+
/// This operation has a time complexity of O(1).
7881
/// </remarks>
82+
/// <param name="value">要查找的值,不能为 null(如果 TValue 是引用类型) / The value to find, cannot be null if TValue is a reference type.</param>
83+
/// <param name="key">查找到的键。如果未找到对应的键,将设置为默认值 / The found key, will be set to the default value if no corresponding key is found.</param>
84+
/// <returns>如果成功找到键,则为 <c>true</c>;否则为 <c>false</c> / <c>true</c> if the key is found; otherwise, <c>false</c>.</returns>
85+
/// <exception cref="ArgumentNullException">当 <paramref name="value"/> 为 null 且 TValue 是引用类型时抛出 / Thrown when <paramref name="value"/> is null and TValue is a reference type.</exception>
7986
public bool TryGetKey(TValue value, out TKey key)
8087
{
8188
ArgumentNullException.ThrowIfNull(value, nameof(value));
@@ -85,13 +92,14 @@ public bool TryGetKey(TValue value, out TKey key)
8592
/// <summary>
8693
/// 尝试根据键获取对应的值。
8794
/// </summary>
88-
/// <param name="key">要查找的键,不能为 null(如果 TKey 是引用类型)。</param>
89-
/// <param name="value">查找到的值。如果未找到对应的值,将设置为默认值。</param>
90-
/// <returns>如果成功找到值,则为 true;否则为 false。</returns>
91-
/// <exception cref="ArgumentNullException">当 <paramref name="key"/> 为 null 且 TKey 是引用类型时抛出</exception>
9295
/// <remarks>
93-
/// 此操作的时间复杂度为 O(1)。
96+
/// Tries to get the value associated with the specified key.
97+
/// This operation has a time complexity of O(1).
9498
/// </remarks>
99+
/// <param name="key">要查找的键,不能为 null(如果 TKey 是引用类型) / The key to find, cannot be null if TKey is a reference type.</param>
100+
/// <param name="value">查找到的值。如果未找到对应的值,将设置为默认值 / The found value, will be set to the default value if no corresponding value is found.</param>
101+
/// <returns>如果成功找到值,则为 <c>true</c>;否则为 <c>false</c> / <c>true</c> if the value is found; otherwise, <c>false</c>.</returns>
102+
/// <exception cref="ArgumentNullException">当 <paramref name="key"/> 为 null 且 TKey 是引用类型时抛出 / Thrown when <paramref name="key"/> is null and TKey is a reference type.</exception>
95103
public bool TryGetValue(TKey key, out TValue value)
96104
{
97105
ArgumentNullException.ThrowIfNull(key, nameof(key));
@@ -102,8 +110,9 @@ public bool TryGetValue(TKey key, out TValue value)
102110
/// 清空双向字典中的所有键值对。
103111
/// </summary>
104112
/// <remarks>
105-
/// 此操作会同时清空正向和反向的映射关系。
106-
/// 清空后,字典的容量会保持不变,但所有元素都会被移除。
113+
/// Clears all key-value pairs from the bidirectional dictionary.
114+
/// This operation clears both forward and reverse mappings.
115+
/// After clearing, the capacity of the dictionary remains the same, but all elements are removed.
107116
/// </remarks>
108117
public void Clear()
109118
{
@@ -114,15 +123,16 @@ public void Clear()
114123
/// <summary>
115124
/// 尝试向双向字典中添加键值对。
116125
/// </summary>
117-
/// <param name="key">要添加的键,不能为 null(如果 TKey 是引用类型)。</param>
118-
/// <param name="value">要添加的值,不能为 null(如果 TValue 是引用类型)。</param>
119-
/// <returns>如果成功添加键值对,则为 true;否则为 false。</returns>
120-
/// <exception cref="ArgumentNullException">当 <paramref name="key"/> 或 <paramref name="value"/> 为 null 且对应类型是引用类型时抛出</exception>
121126
/// <remarks>
122-
/// 如果键或值已存在,则添加失败并返回 false。
123-
/// 添加成功时会同时更新正向和反向的映射关系。
124-
/// 此操作的时间复杂度为 O(1)。
127+
/// Tries to add a key-value pair to the bidirectional dictionary.
128+
/// If the key or value already exists, the addition fails and returns false.
129+
/// When successfully added, both forward and reverse mappings are updated.
130+
/// This operation has a time complexity of O(1).
125131
/// </remarks>
132+
/// <param name="key">要添加的键,不能为 null(如果 TKey 是引用类型) / The key to add, cannot be null if TKey is a reference type.</param>
133+
/// <param name="value">要添加的值,不能为 null(如果 TValue 是引用类型) / The value to add, cannot be null if TValue is a reference type.</param>
134+
/// <returns>如果成功添加键值对,则为 <c>true</c>;否则为 <c>false</c> / <c>true</c> if the key-value pair was added; otherwise, <c>false</c>.</returns>
135+
/// <exception cref="ArgumentNullException">当 <paramref name="key"/> 或 <paramref name="value"/> 为 null 且对应类型是引用类型时抛出 / Thrown when <paramref name="key"/> or <paramref name="value"/> is null and the corresponding type is a reference type.</exception>
126136
public bool TryAdd(TKey key, TValue value)
127137
{
128138
ArgumentNullException.ThrowIfNull(key, nameof(key));
@@ -138,11 +148,14 @@ public bool TryAdd(TKey key, TValue value)
138148
}
139149

140150
/// <summary>
141-
/// 尝试根据键移除键值对
151+
/// 尝试根据键移除键值对
142152
/// </summary>
143-
/// <param name="key">要移除的键,不能为 null(如果 TKey 是引用类型)。</param>
144-
/// <param name="value">查找到的值。如果未找到对应的值,将设置为默认值。</param>
145-
/// <returns>如果成功找到值并移除键值对,则为 true;否则为 false。</returns>
153+
/// <remarks>
154+
/// Tries to remove a key-value pair by key.
155+
/// </remarks>
156+
/// <param name="key">要移除的键,不能为 null(如果 TKey 是引用类型) / The key to remove, cannot be null if TKey is a reference type.</param>
157+
/// <param name="value">查找到的值。如果未找到对应的值,将设置为默认值 / The found value, will be set to the default value if no corresponding value is found.</param>
158+
/// <returns>如果成功找到值并移除键值对,则为 <c>true</c>;否则为 <c>false</c> / <c>true</c> if the value was found and the key-value pair was removed; otherwise, <c>false</c>.</returns>
146159
public bool TryRemoveKey(TKey key, out TValue value)
147160
{
148161
ArgumentNullException.ThrowIfNull(key, nameof(key));
@@ -156,11 +169,14 @@ public bool TryRemoveKey(TKey key, out TValue value)
156169
}
157170

158171
/// <summary>
159-
/// 尝试根据值移除键值对
172+
/// 尝试根据值移除键值对
160173
/// </summary>
161-
/// <param name="value">要移除的值,不能为 null(如果 TValue 是引用类型)。</param>
162-
/// <param name="key">查找到的键。如果未找到对应的值,将设置为默认值。</param>
163-
/// <returns>如果成功找到值并移除键值对,则为 true;否则为 false。</returns>
174+
/// <remarks>
175+
/// Tries to remove a key-value pair by value.
176+
/// </remarks>
177+
/// <param name="value">要移除的值,不能为 null(如果 TValue 是引用类型) / The value to remove, cannot be null if TValue is a reference type.</param>
178+
/// <param name="key">查找到的键。如果未找到对应的值,将设置为默认值 / The found key, will be set to the default value if no corresponding value is found.</param>
179+
/// <returns>如果成功找到值并移除键值对,则为 <c>true</c>;否则为 <c>false</c> / <c>true</c> if the value was found and the key-value pair was removed; otherwise, <c>false</c>.</returns>
164180
public bool TryRemoveValue(TValue value, out TKey key)
165181
{
166182
ArgumentNullException.ThrowIfNull(value, nameof(value));

0 commit comments

Comments
 (0)