Skip to content

Commit 8eb69c7

Browse files
committed
docs(extensions): 为扩展方法添加英文注释以支持国际化
为 ListExtensions、LookupX、NullObject、SpanExtensions、ObjectExtensions 和 ReadOnlySpanExtensions 添加英文 XML 文档注释,使代码库支持多语言文档,便于国际开发者使用和理解 API。
1 parent f7752ce commit 8eb69c7

8 files changed

Lines changed: 1270 additions & 750 deletions

File tree

GameFrameX.Foundation.Extensions/IDictionaryExtensions.cs

Lines changed: 675 additions & 433 deletions
Large diffs are not rendered by default.

GameFrameX.Foundation.Extensions/ListExtensions.cs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,24 @@
3434
namespace GameFrameX.Foundation.Extensions;
3535

3636
/// <summary>
37-
/// 提供List和IEnumerable的扩展方法
37+
/// 提供 List 和 IEnumerable 的扩展方法。
3838
/// </summary>
39+
/// <remarks>
40+
/// Provides extension methods for List and IEnumerable.
41+
/// </remarks>
3942
public static class ListExtensions
4043
{
4144
/// <summary>
42-
/// 异步遍历List中的每个元素并执行指定操作
45+
/// 异步遍历 List 中的每个元素并执行指定操作。
4346
/// </summary>
44-
/// <typeparam name="T">列表元素类型</typeparam>
45-
/// <param name="list">要遍历的列表</param>
46-
/// <param name="func">要执行的异步操作</param>
47-
/// <returns>表示异步操作的任务</returns>
48-
/// <exception cref="ArgumentNullException">当list或func为null时抛出</exception>
47+
/// <remarks>
48+
/// Asynchronically iterates through each element in the list and executes the specified operation.
49+
/// </remarks>
50+
/// <typeparam name="T">列表元素类型 / The type of list elements.</typeparam>
51+
/// <param name="list">要遍历的列表,不能为 <c>null</c> / The list to iterate, cannot be <c>null</c>.</param>
52+
/// <param name="func">要执行的异步操作,不能为 <c>null</c> / The asynchronous operation to execute, cannot be <c>null</c>.</param>
53+
/// <returns>表示异步操作的任务 / A task representing the asynchronous operation.</returns>
54+
/// <exception cref="ArgumentNullException">当 <paramref name="list"/> 或 <paramref name="func"/> 为 <c>null</c> 时抛出 / Thrown when <paramref name="list"/> or <paramref name="func"/> is <c>null</c>.</exception>
4955
public static async Task ForEachAsync<T>(this List<T> list, Func<T, Task> func)
5056
{
5157
ArgumentNullException.ThrowIfNull(list, nameof(list));
@@ -58,13 +64,16 @@ public static async Task ForEachAsync<T>(this List<T> list, Func<T, Task> func)
5864
}
5965

6066
/// <summary>
61-
/// 异步遍历IEnumerable中的每个元素并执行指定操作
67+
/// 异步遍历 IEnumerable 中的每个元素并执行指定操作。
6268
/// </summary>
63-
/// <typeparam name="T">集合元素类型</typeparam>
64-
/// <param name="source">要遍历的集合</param>
65-
/// <param name="action">要执行的异步操作</param>
66-
/// <returns>表示异步操作的任务</returns>
67-
/// <exception cref="ArgumentNullException">当source或action为null时抛出</exception>
69+
/// <remarks>
70+
/// Asynchronously iterates through each element in the IEnumerable and executes the specified operation.
71+
/// </remarks>
72+
/// <typeparam name="T">集合元素类型 / The type of collection elements.</typeparam>
73+
/// <param name="source">要遍历的集合,不能为 <c>null</c> / The collection to iterate, cannot be <c>null</c>.</param>
74+
/// <param name="action">要执行的异步操作,不能为 <c>null</c> / The asynchronous operation to execute, cannot be <c>null</c>.</param>
75+
/// <returns>表示异步操作的任务 / A task representing the asynchronous operation.</returns>
76+
/// <exception cref="ArgumentNullException">当 <paramref name="source"/> 或 <paramref name="action"/> 为 <c>null</c> 时抛出 / Thrown when <paramref name="source"/> or <paramref name="action"/> is <c>null</c>.</exception>
6877
public static async Task ForEachAsync<T>(this IEnumerable<T> source, Func<T, Task> action)
6978
{
7079
ArgumentNullException.ThrowIfNull(source, nameof(source));

GameFrameX.Foundation.Extensions/LookupX.cs

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,25 @@ namespace GameFrameX.Foundation.Extensions;
3838

3939
/// <summary>
4040
/// 表示键和元素之间的多对多关系的集合。
41-
/// 提供了一种高效的方式来存储和检索与特定键关联的多个元素。
4241
/// </summary>
43-
/// <typeparam name="TKey">键的泛型类型。</typeparam>
44-
/// <typeparam name="TElement">元素的泛型类型。</typeparam>
42+
/// <remarks>
43+
/// A collection that represents a many-to-many relationship between keys and elements.
44+
/// Provides an efficient way to store and retrieve multiple elements associated with a specific key.
45+
/// </remarks>
46+
/// <typeparam name="TKey">键的泛型类型 / The generic type of keys.</typeparam>
47+
/// <typeparam name="TElement">元素的泛型类型 / The generic type of elements.</typeparam>
4548
public class LookupX<TKey, TElement> : IEnumerable<List<TElement>>
4649
{
4750
private readonly IDictionary<TKey, List<TElement>> _dictionary;
4851

4952
/// <summary>
5053
/// 使用指定的字典初始化一个新的 <see cref="LookupX&lt;TKey, TElement&gt;" /> 实例。
5154
/// </summary>
52-
/// <param name="dic">用于存储键和元素列表的字典。不能为 null。</param>
53-
/// <exception cref="ArgumentNullException">当 <paramref name="dic"/> 为 null 时抛出。</exception>
55+
/// <remarks>
56+
/// Initializes a new instance of the <see cref="LookupX&lt;TKey, TElement&gt;" /> class with the specified dictionary.
57+
/// </remarks>
58+
/// <param name="dic">用于存储键和元素列表的字典,不能为 null / The dictionary used to store keys and element lists, cannot be null.</param>
59+
/// <exception cref="ArgumentNullException">当 <paramref name="dic"/> 为 null 时抛出 / Thrown when <paramref name="dic"/> is null.</exception>
5460
public LookupX(IDictionary<TKey, List<TElement>> dic)
5561
{
5662
ArgumentNullException.ThrowIfNull(dic, nameof(dic));
@@ -60,8 +66,11 @@ public LookupX(IDictionary<TKey, List<TElement>> dic)
6066
/// <summary>
6167
/// 使用指定的并发字典初始化一个新的 <see cref="LookupX&lt;TKey, TElement&gt;" /> 实例。
6268
/// </summary>
63-
/// <param name="dic">用于存储键和元素列表的并发字典。不能为 null。</param>
64-
/// <exception cref="ArgumentNullException">当 <paramref name="dic"/> 为 null 时抛出。</exception>
69+
/// <remarks>
70+
/// Initializes a new instance of the <see cref="LookupX&lt;TKey, TElement&gt;" /> class with the specified concurrent dictionary.
71+
/// </remarks>
72+
/// <param name="dic">用于存储键和元素列表的并发字典,不能为 null / The concurrent dictionary used to store keys and element lists, cannot be null.</param>
73+
/// <exception cref="ArgumentNullException">当 <paramref name="dic"/> 为 null 时抛出 / Thrown when <paramref name="dic"/> is null.</exception>
6574
public LookupX(ConcurrentDictionary<TKey, List<TElement>> dic)
6675
{
6776
ArgumentNullException.ThrowIfNull(dic, nameof(dic));
@@ -71,7 +80,10 @@ public LookupX(ConcurrentDictionary<TKey, List<TElement>> dic)
7180
/// <summary>
7281
/// 获取集合中的键值对数量。
7382
/// </summary>
74-
/// <value>表示集合中包含的键值对的总数。</value>
83+
/// <remarks>
84+
/// Gets the number of key-value pairs in the collection.
85+
/// </remarks>
86+
/// <value>表示集合中包含的键值对的总数 / The total number of key-value pairs contained in the collection.</value>
7587
public int Count
7688
{
7789
get { return _dictionary.Count; }
@@ -81,9 +93,13 @@ public int Count
8193
/// 获取与指定键关联的元素列表。
8294
/// 如果键不存在,则返回一个空的元素列表。
8395
/// </summary>
84-
/// <param name="key">要查找的键。不能为 null。</param>
85-
/// <returns>与指定键关联的元素列表。如果键不存在,返回空列表。</returns>
86-
/// <exception cref="ArgumentNullException">当 <paramref name="key"/> 为 null 时抛出。</exception>
96+
/// <remarks>
97+
/// Gets the list of elements associated with the specified key.
98+
/// If the key does not exist, returns an empty element list.
99+
/// </remarks>
100+
/// <param name="key">要查找的键,不能为 null / The key to look up, cannot be null.</param>
101+
/// <returns>与指定键关联的元素列表,如果键不存在,返回空列表 / The list of elements associated with the specified key; returns an empty list if the key does not exist.</returns>
102+
/// <exception cref="ArgumentNullException">当 <paramref name="key"/> 为 null 时抛出 / Thrown when <paramref name="key"/> is null.</exception>
87103
public List<TElement> this[TKey key]
88104
{
89105
get
@@ -96,7 +112,10 @@ public List<TElement> this[TKey key]
96112
/// <summary>
97113
/// 返回一个枚举器,该枚举器可以遍历集合中的每个元素列表。
98114
/// </summary>
99-
/// <returns>一个 <see cref="IEnumerator{T}"/> 枚举器,用于遍历集合中的每个元素列表。</returns>
115+
/// <remarks>
116+
/// Returns an enumerator that can iterate through each element list in the collection.
117+
/// </remarks>
118+
/// <returns>一个 <see cref="IEnumerator{T}"/> 枚举器,用于遍历集合中的每个元素列表 / An <see cref="IEnumerator{T}"/> enumerator for iterating through each element list in the collection.</returns>
100119
public IEnumerator<List<TElement>> GetEnumerator()
101120
{
102121
return _dictionary.Values.GetEnumerator();
@@ -105,7 +124,10 @@ public IEnumerator<List<TElement>> GetEnumerator()
105124
/// <summary>
106125
/// 返回一个非泛型枚举器,该枚举器可以遍历集合中的每个元素列表。
107126
/// </summary>
108-
/// <returns>一个 <see cref="IEnumerator"/> 枚举器,用于遍历集合中的每个元素列表。</returns>
127+
/// <remarks>
128+
/// Returns a non-generic enumerator that can iterate through each element list in the collection.
129+
/// </remarks>
130+
/// <returns>一个 <see cref="IEnumerator"/> 枚举器,用于遍历集合中的每个元素列表 / An <see cref="IEnumerator"/> enumerator for iterating through each element list in the collection.</returns>
109131
IEnumerator IEnumerable.GetEnumerator()
110132
{
111133
return GetEnumerator();
@@ -114,9 +136,12 @@ IEnumerator IEnumerable.GetEnumerator()
114136
/// <summary>
115137
/// 判断集合中是否包含指定的键。
116138
/// </summary>
117-
/// <param name="key">要检查的键。不能为 null。</param>
118-
/// <returns>如果集合中包含指定的键,则返回 <c>true</c>;否则返回 <c>false</c>。</returns>
119-
/// <exception cref="ArgumentNullException">当 <paramref name="key"/> 为 null 时抛出。</exception>
139+
/// <remarks>
140+
/// Determines whether the collection contains the specified key.
141+
/// </remarks>
142+
/// <param name="key">要检查的键,不能为 null / The key to check, cannot be null.</param>
143+
/// <returns>如果集合中包含指定的键,则返回 <c>true</c>;否则返回 <c>false</c> / <c>true</c> if the collection contains the specified key; otherwise, <c>false</c>.</returns>
144+
/// <exception cref="ArgumentNullException">当 <paramref name="key"/> 为 null 时抛出 / Thrown when <paramref name="key"/> is null.</exception>
120145
public bool Contains(TKey key)
121146
{
122147
ArgumentNullException.ThrowIfNull(key, nameof(key));

GameFrameX.Foundation.Extensions/NullObject.cs

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,19 @@ namespace GameFrameX.Foundation.Extensions;
3939
/// <summary>
4040
/// 表示可为空的对象。
4141
/// </summary>
42-
/// <typeparam name="T">对象的类型。</typeparam>
42+
/// <remarks>
43+
/// Represents an object that can be null.
44+
/// </remarks>
45+
/// <typeparam name="T">对象的类型 / The type of the object.</typeparam>
4346
public readonly record struct NullObject<T> : IComparable, IComparable<T>, IEquatable<NullObject<T>>
4447
{
4548
/// <summary>
4649
/// 初始化一个新的 <see cref="NullObject{T}" /> 实例。
4750
/// </summary>
48-
/// <param name="item">对象的值。</param>
51+
/// <remarks>
52+
/// Initializes a new instance of the <see cref="NullObject{T}" /> struct.
53+
/// </remarks>
54+
/// <param name="item">对象的值 / The value of the object.</param>
4955
public NullObject(T item)
5056
{
5157
Item = item;
@@ -54,6 +60,9 @@ public NullObject(T item)
5460
/// <summary>
5561
/// 获取一个表示空值的 <see cref="NullObject{T}" /> 实例。
5662
/// </summary>
63+
/// <remarks>
64+
/// Gets a <see cref="NullObject{T}" /> instance representing a null value.
65+
/// </remarks>
5766
public static NullObject<T> Null
5867
{
5968
get { return new NullObject<T>(); }
@@ -62,14 +71,21 @@ public static NullObject<T> Null
6271
/// <summary>
6372
/// 获取对象的值。
6473
/// </summary>
74+
/// <remarks>
75+
/// Gets the value of the object.
76+
/// </remarks>
77+
/// <value>对象的值 / The value of the object.</value>
6578
public T Item { get; }
6679

6780
/// <summary>
6881
/// 比较当前对象与另一个对象。
6982
/// </summary>
70-
/// <param name="value">要比较的对象。</param>
71-
/// <returns>一个整数,指示当前对象与 <paramref name="value" /> 的相对顺序。</returns>
72-
/// <exception cref="ArgumentException">当 Item 为 null 且无法进行比较时抛出。</exception>
83+
/// <remarks>
84+
/// Compares the current object with another object.
85+
/// </remarks>
86+
/// <param name="value">要比较的对象 / The object to compare with.</param>
87+
/// <returns>一个整数,指示当前对象与 <paramref name="value" /> 的相对顺序 / An integer indicating the relative order of the current object and <paramref name="value" />.</returns>
88+
/// <exception cref="ArgumentException">当 Item 为 null 且无法进行比较时抛出 / Thrown when Item is null and cannot be compared.</exception>
7389
public int CompareTo(object value)
7490
{
7591
if (value is null)
@@ -113,9 +129,12 @@ public int CompareTo(object value)
113129
/// <summary>
114130
/// 比较当前对象与同一类型的另一个对象。
115131
/// </summary>
116-
/// <param name="other">要比较的对象。</param>
117-
/// <returns>一个整数,指示当前对象与 <paramref name="other" /> 的相对顺序。</returns>
118-
/// <exception cref="ArgumentException">当 Item 为 null 且无法进行比较时抛出。</exception>
132+
/// <remarks>
133+
/// Compares the current object with another object of the same type.
134+
/// </remarks>
135+
/// <param name="other">要比较的对象 / The object to compare with.</param>
136+
/// <returns>一个整数,指示当前对象与 <paramref name="other" /> 的相对顺序 / An integer indicating the relative order of the current object and <paramref name="other" />.</returns>
137+
/// <exception cref="ArgumentException">当 Item 为 null 且无法进行比较时抛出 / Thrown when Item is null and cannot be compared.</exception>
119138
public int CompareTo(T other)
120139
{
121140
if (Item is null && other is null)
@@ -144,8 +163,11 @@ public int CompareTo(T other)
144163
/// <summary>
145164
/// 指示当前对象是否等于同一类型的另一个对象。
146165
/// </summary>
147-
/// <param name="other">一个与此对象进行比较的对象。</param>
148-
/// <returns>如果当前对象等于 <paramref name="other" /> 参数,则为 true;否则为 false。</returns>
166+
/// <remarks>
167+
/// Indicates whether the current object is equal to another object of the same type.
168+
/// </remarks>
169+
/// <param name="other">一个与此对象进行比较的对象 / An object to compare with this object.</param>
170+
/// <returns>如果当前对象等于 <paramref name="other" /> 参数,则为 <c>true</c>;否则为 <c>false</c> / <c>true</c> if the current object equals the <paramref name="other" /> parameter; otherwise, <c>false</c>.</returns>
149171
public bool Equals(NullObject<T> other)
150172
{
151173
return EqualityComparer<T>.Default.Equals(Item, other.Item);
@@ -154,7 +176,10 @@ public bool Equals(NullObject<T> other)
154176
/// <summary>
155177
/// 将 <see cref="NullObject{T}" /> 隐式转换为类型 <typeparamref name="T" />。
156178
/// </summary>
157-
/// <param name="nullObject">要转换的 <see cref="NullObject{T}" /> 实例。</param>
179+
/// <remarks>
180+
/// Implicitly converts a <see cref="NullObject{T}" /> to type <typeparamref name="T" />.
181+
/// </remarks>
182+
/// <param name="nullObject">要转换的 <see cref="NullObject{T}" /> 实例 / The <see cref="NullObject{T}" /> instance to convert.</param>
158183
public static implicit operator T(NullObject<T> nullObject)
159184
{
160185
return nullObject.Item;
@@ -163,7 +188,10 @@ public static implicit operator T(NullObject<T> nullObject)
163188
/// <summary>
164189
/// 将类型 <typeparamref name="T" /> 隐式转换为 <see cref="NullObject{T}" />。
165190
/// </summary>
166-
/// <param name="item">要转换的值。</param>
191+
/// <remarks>
192+
/// Implicitly converts a value of type <typeparamref name="T" /> to <see cref="NullObject{T}" />.
193+
/// </remarks>
194+
/// <param name="item">要转换的值 / The value to convert.</param>
167195
public static implicit operator NullObject<T>(T item)
168196
{
169197
return new NullObject<T>(item);
@@ -172,7 +200,10 @@ public static implicit operator NullObject<T>(T item)
172200
/// <summary>
173201
/// 返回对象的字符串表示形式。
174202
/// </summary>
175-
/// <returns>对象的字符串表示形式,如果对象为 null,则返回 "NULL"。</returns>
203+
/// <remarks>
204+
/// Returns the string representation of the object.
205+
/// </remarks>
206+
/// <returns>对象的字符串表示形式,如果对象为 null,则返回 "NULL" / The string representation of the object, or "NULL" if the object is null.</returns>
176207
public override string ToString()
177208
{
178209
return Item != null ? Item.ToString() : "NULL";
@@ -181,7 +212,10 @@ public override string ToString()
181212
/// <summary>
182213
/// 返回当前对象的哈希代码。
183214
/// </summary>
184-
/// <returns>当前对象的哈希代码。</returns>
215+
/// <remarks>
216+
/// Returns the hash code of the current object.
217+
/// </remarks>
218+
/// <returns>当前对象的哈希代码 / The hash code of the current object.</returns>
185219
public override int GetHashCode()
186220
{
187221
return EqualityComparer<T>.Default.GetHashCode(Item);

0 commit comments

Comments
 (0)