11namespace GameFrameX . Foundation . Extensions ;
22
33/// <summary>
4- /// 值可被Dispose的字典类型
4+ /// 值可被Dispose的字典类型。
55/// </summary>
6- /// <typeparam name="TKey">键的类型。</typeparam>
7- /// <typeparam name="TValue">值的类型,必须实现IDisposable接口。</typeparam>
6+ /// <remarks>
7+ /// A dictionary type whose values can be disposed.
8+ /// </remarks>
9+ /// <typeparam name="TKey">键的类型 / The type of the key.</typeparam>
10+ /// <typeparam name="TValue">值的类型,必须实现IDisposable接口 / The type of the value, must implement IDisposable interface.</typeparam>
811public class DisposableDictionary < TKey , TValue > : NullableDictionary < TKey , TValue > , IDisposable where TValue : IDisposable
912{
1013 private bool _isDisposed ;
1114
1215 /// <summary>
1316 /// 初始化一个新的 <see cref="DisposableDictionary{TKey, TValue}" /> 实例。
1417 /// </summary>
18+ /// <remarks>
19+ /// Initializes a new instance of the <see cref="DisposableDictionary{TKey, TValue}" /> class.
20+ /// </remarks>
1521 public DisposableDictionary ( )
1622 {
1723 }
1824
1925 /// <summary>
2026 /// 使用指定的默认值初始化一个新的 <see cref="DisposableDictionary{TKey, TValue}" /> 实例。
2127 /// </summary>
22- /// <param name="fallbackValue">当键不存在时返回的默认值。</param>
28+ /// <remarks>
29+ /// Initializes a new instance of the <see cref="DisposableDictionary{TKey, TValue}" /> class with the specified default value.
30+ /// </remarks>
31+ /// <param name="fallbackValue">当键不存在时返回的默认值 / The default value to return when a key does not exist.</param>
2332 public DisposableDictionary ( TValue fallbackValue )
2433 {
2534 FallbackValue = fallbackValue ;
@@ -28,8 +37,11 @@ public DisposableDictionary(TValue fallbackValue)
2837 /// <summary>
2938 /// 使用指定的字典初始化一个新的 <see cref="DisposableDictionary{TKey, TValue}" /> 实例。
3039 /// </summary>
31- /// <param name="dictionary">用于初始化的字典,不能为 null。</param>
32- /// <exception cref="ArgumentNullException">当 dictionary 为 null 时抛出。</exception>
40+ /// <remarks>
41+ /// Initializes a new instance of the <see cref="DisposableDictionary{TKey, TValue}" /> class with the specified dictionary.
42+ /// </remarks>
43+ /// <param name="dictionary">用于初始化的字典,不能为 null / The dictionary to initialize with, cannot be null.</param>
44+ /// <exception cref="ArgumentNullException">当 <paramref name="dictionary"/> 为 null 时抛出 / Thrown when <paramref name="dictionary"/> is null.</exception>
3345 public DisposableDictionary ( Dictionary < TKey , TValue > dictionary )
3446 {
3547 ArgumentNullException . ThrowIfNull ( dictionary , nameof ( dictionary ) ) ;
@@ -43,17 +55,23 @@ public DisposableDictionary(Dictionary<TKey, TValue> dictionary)
4355 /// <summary>
4456 /// 使用指定的初始容量初始化一个新的 <see cref="DisposableDictionary{TKey, TValue}" /> 实例。
4557 /// </summary>
46- /// <param name="capacity">字典的初始容量,必须大于等于 0。</param>
47- /// <exception cref="ArgumentOutOfRangeException">当 capacity 小于 0 时抛出。</exception>
58+ /// <remarks>
59+ /// Initializes a new instance of the <see cref="DisposableDictionary{TKey, TValue}" /> class with the specified initial capacity.
60+ /// </remarks>
61+ /// <param name="capacity">字典的初始容量,必须大于等于 0 / The initial capacity of the dictionary, must be greater than or equal to 0.</param>
62+ /// <exception cref="ArgumentOutOfRangeException">当 <paramref name="capacity"/> 小于 0 时抛出 / Thrown when <paramref name="capacity"/> is less than 0.</exception>
4863 public DisposableDictionary ( int capacity ) : base ( capacity )
4964 {
5065 }
5166
5267 /// <summary>
5368 /// 使用指定的字典初始化一个新的 <see cref="DisposableDictionary{TKey, TValue}" /> 实例。
5469 /// </summary>
55- /// <param name="dictionary">用于初始化的字典,不能为 null。</param>
56- /// <exception cref="ArgumentNullException">当 dictionary 为 null 时抛出。</exception>
70+ /// <remarks>
71+ /// Initializes a new instance of the <see cref="DisposableDictionary{TKey, TValue}" /> class with the specified dictionary.
72+ /// </remarks>
73+ /// <param name="dictionary">用于初始化的字典,不能为 null / The dictionary to initialize with, cannot be null.</param>
74+ /// <exception cref="ArgumentNullException">当 <paramref name="dictionary"/> 为 null 时抛出 / Thrown when <paramref name="dictionary"/> is null.</exception>
5775 public DisposableDictionary ( IDictionary < NullObject < TKey > , TValue > dictionary ) : base ( dictionary )
5876 {
5977 ArgumentNullException . ThrowIfNull ( dictionary , nameof ( dictionary ) ) ;
@@ -62,6 +80,9 @@ public DisposableDictionary(IDictionary<NullObject<TKey>, TValue> dictionary) :
6280 /// <summary>
6381 /// 释放资源。
6482 /// </summary>
83+ /// <remarks>
84+ /// Releases all resources used by this instance.
85+ /// </remarks>
6586 public void Dispose ( )
6687 {
6788 if ( _isDisposed )
@@ -77,6 +98,9 @@ public void Dispose()
7798 /// <summary>
7899 /// 终结器,确保未释放的资源在对象被垃圾回收时被释放。
79100 /// </summary>
101+ /// <remarks>
102+ /// Finalizer to ensure unmanaged resources are released when the object is garbage collected.
103+ /// </remarks>
80104 ~ DisposableDictionary ( )
81105 {
82106 Dispose ( false ) ;
@@ -85,7 +109,10 @@ public void Dispose()
85109 /// <summary>
86110 /// 释放资源。
87111 /// </summary>
88- /// <param name="disposing">指示是否应释放托管资源。</param>
112+ /// <remarks>
113+ /// Releases the unmanaged resources used by the <see cref="DisposableDictionary{TKey, TValue}"/> and optionally releases the managed resources.
114+ /// </remarks>
115+ /// <param name="disposing">指示是否应释放托管资源 / true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
89116 protected virtual void Dispose ( bool disposing )
90117 {
91118 foreach ( var s in Values . Where ( v => v != null ) )
0 commit comments