|
@@ -5,1152 +5,1151 @@ using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
-namespace Masuit.Tools
|
|
|
+namespace Masuit.Tools;
|
|
|
+
|
|
|
+public static class IDictionaryExtensions
|
|
|
{
|
|
|
- public static class IDictionaryExtensions
|
|
|
- {
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- public static void AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ public static void AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that)
|
|
|
+ {
|
|
|
+ foreach (var item in that)
|
|
|
{
|
|
|
- foreach (var item in that)
|
|
|
- {
|
|
|
- @this[item.Key] = item.Value;
|
|
|
- }
|
|
|
+ @this[item.Key] = item.Value;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- public static void AddOrUpdate<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ public static void AddOrUpdate<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that)
|
|
|
+ {
|
|
|
+ foreach (var item in that)
|
|
|
{
|
|
|
- foreach (var item in that)
|
|
|
- {
|
|
|
- @this[item.Key] = item.Value;
|
|
|
- }
|
|
|
+ @this[item.Key] = item.Value;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- public static void AddOrUpdate<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ public static void AddOrUpdate<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that)
|
|
|
+ {
|
|
|
+ foreach (var item in that)
|
|
|
{
|
|
|
- foreach (var item in that)
|
|
|
- {
|
|
|
- @this[item.Key] = item.Value;
|
|
|
- }
|
|
|
+ @this[item.Key] = item.Value;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- public static void AddOrUpdateTo<TKey, TValue>(this IDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ public static void AddOrUpdateTo<TKey, TValue>(this IDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that)
|
|
|
+ {
|
|
|
+ foreach (var item in @this)
|
|
|
{
|
|
|
- foreach (var item in @this)
|
|
|
- {
|
|
|
- that[item.Key] = item.Value;
|
|
|
- }
|
|
|
+ that[item.Key] = item.Value;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- public static void AddOrUpdateTo<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ public static void AddOrUpdateTo<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that)
|
|
|
+ {
|
|
|
+ foreach (var item in @this)
|
|
|
{
|
|
|
- foreach (var item in @this)
|
|
|
- {
|
|
|
- that[item.Key] = item.Value;
|
|
|
- }
|
|
|
+ that[item.Key] = item.Value;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- public static void AddOrUpdateTo<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ public static void AddOrUpdateTo<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that)
|
|
|
+ {
|
|
|
+ foreach (var item in @this)
|
|
|
{
|
|
|
- foreach (var item in @this)
|
|
|
- {
|
|
|
- that[item.Key] = item.Value;
|
|
|
- }
|
|
|
+ that[item.Key] = item.Value;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key">键</param>
|
|
|
- /// <param name="addValue">添加时的值</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static TValue AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> @this, TKey key, TValue addValue, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key">键</param>
|
|
|
+ /// <param name="addValue">添加时的值</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static TValue AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> @this, TKey key, TValue addValue, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ {
|
|
|
+ if ([email protected](key, addValue))
|
|
|
{
|
|
|
- if ([email protected](key, addValue))
|
|
|
- {
|
|
|
- @this[key] = updateValueFactory(key, @this[key]);
|
|
|
- }
|
|
|
-
|
|
|
- return @this[key];
|
|
|
+ @this[key] = updateValueFactory(key, @this[key]);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key">键</param>
|
|
|
- /// <param name="addValue">添加时的值</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static TValue AddOrUpdate<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, TKey key, TValue addValue, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
- {
|
|
|
- if ([email protected](key, addValue))
|
|
|
- {
|
|
|
- @this[key] = updateValueFactory(key, @this[key]);
|
|
|
- }
|
|
|
-
|
|
|
- return @this[key];
|
|
|
- }
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key">键</param>
|
|
|
- /// <param name="addValue">添加时的值</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static TValue AddOrUpdate<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, TKey key, TValue addValue, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key">键</param>
|
|
|
+ /// <param name="addValue">添加时的值</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static TValue AddOrUpdate<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, TKey key, TValue addValue, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ {
|
|
|
+ if ([email protected](key, addValue))
|
|
|
{
|
|
|
- if ([email protected](key, addValue))
|
|
|
- {
|
|
|
- @this[key] = updateValueFactory(key, @this[key]);
|
|
|
- }
|
|
|
-
|
|
|
- return @this[key];
|
|
|
+ @this[key] = updateValueFactory(key, @this[key]);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key">键</param>
|
|
|
- /// <param name="addValue">添加时的值</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static async Task<TValue> AddOrUpdateAsync<TKey, TValue>(this IDictionary<TKey, TValue> @this, TKey key, TValue addValue, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
- {
|
|
|
- if ([email protected](key, addValue))
|
|
|
- {
|
|
|
- @this[key] = await updateValueFactory(key, @this[key]);
|
|
|
- }
|
|
|
-
|
|
|
- return @this[key];
|
|
|
- }
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key">键</param>
|
|
|
- /// <param name="addValue">添加时的值</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static async Task<TValue> AddOrUpdateAsync<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, TKey key, TValue addValue, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key">键</param>
|
|
|
+ /// <param name="addValue">添加时的值</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static TValue AddOrUpdate<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, TKey key, TValue addValue, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ {
|
|
|
+ if ([email protected](key, addValue))
|
|
|
{
|
|
|
- if ([email protected](key, addValue))
|
|
|
- {
|
|
|
- @this[key] = await updateValueFactory(key, @this[key]);
|
|
|
- }
|
|
|
-
|
|
|
- return @this[key];
|
|
|
+ @this[key] = updateValueFactory(key, @this[key]);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key">键</param>
|
|
|
- /// <param name="addValue">添加时的值</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static async Task<TValue> AddOrUpdateAsync<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, TKey key, TValue addValue, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
- {
|
|
|
- if ([email protected](key, addValue))
|
|
|
- {
|
|
|
- @this[key] = await updateValueFactory(key, @this[key]);
|
|
|
- }
|
|
|
-
|
|
|
- return @this[key];
|
|
|
- }
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key">键</param>
|
|
|
- /// <param name="addValue">添加时的值</param>
|
|
|
- /// <param name="updateValue">更新时的值</param>
|
|
|
- public static TValue AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> @this, TKey key, TValue addValue, TValue updateValue)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key">键</param>
|
|
|
+ /// <param name="addValue">添加时的值</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static async Task<TValue> AddOrUpdateAsync<TKey, TValue>(this IDictionary<TKey, TValue> @this, TKey key, TValue addValue, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ {
|
|
|
+ if ([email protected](key, addValue))
|
|
|
{
|
|
|
- if ([email protected](key, addValue))
|
|
|
- {
|
|
|
- @this[key] = updateValue;
|
|
|
- }
|
|
|
-
|
|
|
- return @this[key];
|
|
|
+ @this[key] = await updateValueFactory(key, @this[key]);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key">键</param>
|
|
|
- /// <param name="addValue">添加时的值</param>
|
|
|
- /// <param name="updateValue">更新时的值</param>
|
|
|
- public static TValue AddOrUpdate<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, TKey key, TValue addValue, TValue updateValue)
|
|
|
- {
|
|
|
- if ([email protected](key, addValue))
|
|
|
- {
|
|
|
- @this[key] = updateValue;
|
|
|
- }
|
|
|
-
|
|
|
- return @this[key];
|
|
|
- }
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key">键</param>
|
|
|
- /// <param name="addValue">添加时的值</param>
|
|
|
- /// <param name="updateValue">更新时的值</param>
|
|
|
- public static TValue AddOrUpdate<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, TKey key, TValue addValue, TValue updateValue)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key">键</param>
|
|
|
+ /// <param name="addValue">添加时的值</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static async Task<TValue> AddOrUpdateAsync<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, TKey key, TValue addValue, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ {
|
|
|
+ if ([email protected](key, addValue))
|
|
|
{
|
|
|
- if ([email protected](key, addValue))
|
|
|
- {
|
|
|
- @this[key] = updateValue;
|
|
|
- }
|
|
|
-
|
|
|
- return @this[key];
|
|
|
+ @this[key] = await updateValueFactory(key, @this[key]);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static void AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
- {
|
|
|
- foreach (var item in that)
|
|
|
- {
|
|
|
- AddOrUpdate(@this, item.Key, item.Value, updateValueFactory);
|
|
|
- }
|
|
|
- }
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static void AddOrUpdate<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key">键</param>
|
|
|
+ /// <param name="addValue">添加时的值</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static async Task<TValue> AddOrUpdateAsync<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, TKey key, TValue addValue, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ {
|
|
|
+ if ([email protected](key, addValue))
|
|
|
{
|
|
|
- foreach (var item in that)
|
|
|
- {
|
|
|
- AddOrUpdate(@this, item.Key, item.Value, updateValueFactory);
|
|
|
- }
|
|
|
+ @this[key] = await updateValueFactory(key, @this[key]);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static void AddOrUpdate<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
- {
|
|
|
- foreach (var item in that)
|
|
|
- {
|
|
|
- AddOrUpdate(@this, item.Key, item.Value, updateValueFactory);
|
|
|
- }
|
|
|
- }
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static Task AddOrUpdateAsync<TKey, TValue>(this IDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key">键</param>
|
|
|
+ /// <param name="addValue">添加时的值</param>
|
|
|
+ /// <param name="updateValue">更新时的值</param>
|
|
|
+ public static TValue AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> @this, TKey key, TValue addValue, TValue updateValue)
|
|
|
+ {
|
|
|
+ if ([email protected](key, addValue))
|
|
|
{
|
|
|
- return that.ForeachAsync(item => AddOrUpdateAsync(@this, item.Key, item.Value, updateValueFactory));
|
|
|
+ @this[key] = updateValue;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static Task AddOrUpdateAsync<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key">键</param>
|
|
|
+ /// <param name="addValue">添加时的值</param>
|
|
|
+ /// <param name="updateValue">更新时的值</param>
|
|
|
+ public static TValue AddOrUpdate<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, TKey key, TValue addValue, TValue updateValue)
|
|
|
+ {
|
|
|
+ if ([email protected](key, addValue))
|
|
|
{
|
|
|
- return that.ForeachAsync(item => AddOrUpdateAsync(@this, item.Key, item.Value, updateValueFactory));
|
|
|
+ @this[key] = updateValue;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static Task AddOrUpdateAsync<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key">键</param>
|
|
|
+ /// <param name="addValue">添加时的值</param>
|
|
|
+ /// <param name="updateValue">更新时的值</param>
|
|
|
+ public static TValue AddOrUpdate<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, TKey key, TValue addValue, TValue updateValue)
|
|
|
+ {
|
|
|
+ if ([email protected](key, addValue))
|
|
|
{
|
|
|
- return that.ForeachAsync(item => AddOrUpdateAsync(@this, item.Key, item.Value, updateValueFactory));
|
|
|
+ @this[key] = updateValue;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static void AddOrUpdateTo<TKey, TValue>(this IDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static void AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ {
|
|
|
+ foreach (var item in that)
|
|
|
{
|
|
|
- foreach (var item in @this)
|
|
|
- {
|
|
|
- AddOrUpdate(that, item.Key, item.Value, updateValueFactory);
|
|
|
- }
|
|
|
+ AddOrUpdate(@this, item.Key, item.Value, updateValueFactory);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static void AddOrUpdateTo<TKey, TValue>(this IDictionary<TKey, TValue> @this, NullableDictionary<TKey, TValue> that, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static void AddOrUpdate<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ {
|
|
|
+ foreach (var item in that)
|
|
|
{
|
|
|
- foreach (var item in @this)
|
|
|
- {
|
|
|
- AddOrUpdate(that, item.Key, item.Value, updateValueFactory);
|
|
|
- }
|
|
|
+ AddOrUpdate(@this, item.Key, item.Value, updateValueFactory);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static void AddOrUpdateTo<TKey, TValue>(this IDictionary<TKey, TValue> @this, NullableConcurrentDictionary<TKey, TValue> that, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static void AddOrUpdate<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ {
|
|
|
+ foreach (var item in that)
|
|
|
{
|
|
|
- foreach (var item in @this)
|
|
|
- {
|
|
|
- AddOrUpdate(that, item.Key, item.Value, updateValueFactory);
|
|
|
- }
|
|
|
+ AddOrUpdate(@this, item.Key, item.Value, updateValueFactory);
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static Task AddOrUpdateAsync<TKey, TValue>(this IDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ {
|
|
|
+ return that.ForeachAsync(item => AddOrUpdateAsync(@this, item.Key, item.Value, updateValueFactory));
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static Task AddOrUpdateAsync<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ {
|
|
|
+ return that.ForeachAsync(item => AddOrUpdateAsync(@this, item.Key, item.Value, updateValueFactory));
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static Task AddOrUpdateAsync<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ {
|
|
|
+ return that.ForeachAsync(item => AddOrUpdateAsync(@this, item.Key, item.Value, updateValueFactory));
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static Task AddOrUpdateAsyncTo<TKey, TValue>(this IDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static void AddOrUpdateTo<TKey, TValue>(this IDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ {
|
|
|
+ foreach (var item in @this)
|
|
|
{
|
|
|
- return @this.ForeachAsync(item => AddOrUpdateAsync(that, item.Key, item.Value, updateValueFactory));
|
|
|
+ AddOrUpdate(that, item.Key, item.Value, updateValueFactory);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static Task AddOrUpdateAsyncTo<TKey, TValue>(this IDictionary<TKey, TValue> @this, NullableDictionary<TKey, TValue> that, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static void AddOrUpdateTo<TKey, TValue>(this IDictionary<TKey, TValue> @this, NullableDictionary<TKey, TValue> that, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ {
|
|
|
+ foreach (var item in @this)
|
|
|
{
|
|
|
- return @this.ForeachAsync(item => AddOrUpdateAsync(that, item.Key, item.Value, updateValueFactory));
|
|
|
+ AddOrUpdate(that, item.Key, item.Value, updateValueFactory);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="that">另一个字典集</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static Task AddOrUpdateAsyncTo<TKey, TValue>(this IDictionary<TKey, TValue> @this, NullableConcurrentDictionary<TKey, TValue> that, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static void AddOrUpdateTo<TKey, TValue>(this IDictionary<TKey, TValue> @this, NullableConcurrentDictionary<TKey, TValue> that, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ {
|
|
|
+ foreach (var item in @this)
|
|
|
{
|
|
|
- return @this.ForeachAsync(item => AddOrUpdateAsync(that, item.Key, item.Value, updateValueFactory));
|
|
|
+ AddOrUpdate(that, item.Key, item.Value, updateValueFactory);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key">键</param>
|
|
|
- /// <param name="addValueFactory">添加时的操作</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static TValue AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> @this, TKey key, Func<TKey, TValue> addValueFactory, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
- {
|
|
|
- if ([email protected](key, addValueFactory(key)))
|
|
|
- {
|
|
|
- @this[key] = updateValueFactory(key, @this[key]);
|
|
|
- }
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static Task AddOrUpdateAsyncTo<TKey, TValue>(this IDictionary<TKey, TValue> @this, IDictionary<TKey, TValue> that, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ {
|
|
|
+ return @this.ForeachAsync(item => AddOrUpdateAsync(that, item.Key, item.Value, updateValueFactory));
|
|
|
+ }
|
|
|
|
|
|
- return @this[key];
|
|
|
- }
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static Task AddOrUpdateAsyncTo<TKey, TValue>(this IDictionary<TKey, TValue> @this, NullableDictionary<TKey, TValue> that, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ {
|
|
|
+ return @this.ForeachAsync(item => AddOrUpdateAsync(that, item.Key, item.Value, updateValueFactory));
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key">键</param>
|
|
|
- /// <param name="addValueFactory">添加时的操作</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static TValue AddOrUpdate<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, TKey key, Func<TKey, TValue> addValueFactory, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
- {
|
|
|
- if ([email protected](key, addValueFactory(key)))
|
|
|
- {
|
|
|
- @this[key] = updateValueFactory(key, @this[key]);
|
|
|
- }
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="that">另一个字典集</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static Task AddOrUpdateAsyncTo<TKey, TValue>(this IDictionary<TKey, TValue> @this, NullableConcurrentDictionary<TKey, TValue> that, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ {
|
|
|
+ return @this.ForeachAsync(item => AddOrUpdateAsync(that, item.Key, item.Value, updateValueFactory));
|
|
|
+ }
|
|
|
|
|
|
- return @this[key];
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key">键</param>
|
|
|
+ /// <param name="addValueFactory">添加时的操作</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static TValue AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> @this, TKey key, Func<TKey, TValue> addValueFactory, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ {
|
|
|
+ if ([email protected](key, addValueFactory(key)))
|
|
|
+ {
|
|
|
+ @this[key] = updateValueFactory(key, @this[key]);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key">键</param>
|
|
|
- /// <param name="addValueFactory">添加时的操作</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static TValue AddOrUpdate<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, TKey key, Func<TKey, TValue> addValueFactory, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
- {
|
|
|
- if ([email protected](key, addValueFactory(key)))
|
|
|
- {
|
|
|
- @this[key] = updateValueFactory(key, @this[key]);
|
|
|
- }
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
|
|
|
- return @this[key];
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key">键</param>
|
|
|
+ /// <param name="addValueFactory">添加时的操作</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static TValue AddOrUpdate<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, TKey key, Func<TKey, TValue> addValueFactory, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ {
|
|
|
+ if ([email protected](key, addValueFactory(key)))
|
|
|
+ {
|
|
|
+ @this[key] = updateValueFactory(key, @this[key]);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key">键</param>
|
|
|
- /// <param name="addValueFactory">添加时的操作</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static async Task<TValue> AddOrUpdateAsync<TKey, TValue>(this IDictionary<TKey, TValue> @this, TKey key, Func<TKey, Task<TValue>> addValueFactory, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
- {
|
|
|
- if ([email protected](key, await addValueFactory(key)))
|
|
|
- {
|
|
|
- @this[key] = await updateValueFactory(key, @this[key]);
|
|
|
- }
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
|
|
|
- return @this[key];
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key">键</param>
|
|
|
+ /// <param name="addValueFactory">添加时的操作</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static TValue AddOrUpdate<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, TKey key, Func<TKey, TValue> addValueFactory, Func<TKey, TValue, TValue> updateValueFactory)
|
|
|
+ {
|
|
|
+ if ([email protected](key, addValueFactory(key)))
|
|
|
+ {
|
|
|
+ @this[key] = updateValueFactory(key, @this[key]);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key">键</param>
|
|
|
- /// <param name="addValueFactory">添加时的操作</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static async Task<TValue> AddOrUpdateAsync<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, TKey key, Func<TKey, Task<TValue>> addValueFactory, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
- {
|
|
|
- if ([email protected](key, await addValueFactory(key)))
|
|
|
- {
|
|
|
- @this[key] = await updateValueFactory(key, @this[key]);
|
|
|
- }
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
|
|
|
- return @this[key];
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key">键</param>
|
|
|
+ /// <param name="addValueFactory">添加时的操作</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static async Task<TValue> AddOrUpdateAsync<TKey, TValue>(this IDictionary<TKey, TValue> @this, TKey key, Func<TKey, Task<TValue>> addValueFactory, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ {
|
|
|
+ if ([email protected](key, await addValueFactory(key)))
|
|
|
+ {
|
|
|
+ @this[key] = await updateValueFactory(key, @this[key]);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 添加或更新键值对
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key">键</param>
|
|
|
- /// <param name="addValueFactory">添加时的操作</param>
|
|
|
- /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
- public static async Task<TValue> AddOrUpdateAsync<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, TKey key, Func<TKey, Task<TValue>> addValueFactory, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
- {
|
|
|
- if ([email protected](key, await addValueFactory(key)))
|
|
|
- {
|
|
|
- @this[key] = await updateValueFactory(key, @this[key]);
|
|
|
- }
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
|
|
|
- return @this[key];
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key">键</param>
|
|
|
+ /// <param name="addValueFactory">添加时的操作</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static async Task<TValue> AddOrUpdateAsync<TKey, TValue>(this NullableDictionary<TKey, TValue> @this, TKey key, Func<TKey, Task<TValue>> addValueFactory, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ {
|
|
|
+ if ([email protected](key, await addValueFactory(key)))
|
|
|
+ {
|
|
|
+ @this[key] = await updateValueFactory(key, @this[key]);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 获取或添加
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key"></param>
|
|
|
- /// <param name="addValueFactory"></param>
|
|
|
- public static TValue GetOrAdd<TKey, TValue>(this IDictionary<TKey, TValue> @this, TKey key, Func<TValue> addValueFactory)
|
|
|
- {
|
|
|
- if ([email protected](key))
|
|
|
- {
|
|
|
- @this[key] = addValueFactory();
|
|
|
- }
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
|
|
|
- return @this[key];
|
|
|
+ /// <summary>
|
|
|
+ /// 添加或更新键值对
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key">键</param>
|
|
|
+ /// <param name="addValueFactory">添加时的操作</param>
|
|
|
+ /// <param name="updateValueFactory">更新时的操作</param>
|
|
|
+ public static async Task<TValue> AddOrUpdateAsync<TKey, TValue>(this NullableConcurrentDictionary<TKey, TValue> @this, TKey key, Func<TKey, Task<TValue>> addValueFactory, Func<TKey, TValue, Task<TValue>> updateValueFactory)
|
|
|
+ {
|
|
|
+ if ([email protected](key, await addValueFactory(key)))
|
|
|
+ {
|
|
|
+ @this[key] = await updateValueFactory(key, @this[key]);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 获取或添加
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key"></param>
|
|
|
- /// <param name="addValueFactory"></param>
|
|
|
- public static async Task<TValue> GetOrAddAsync<TKey, TValue>(this IDictionary<TKey, TValue> @this, TKey key, Func<Task<TValue>> addValueFactory)
|
|
|
- {
|
|
|
- if ([email protected](key))
|
|
|
- {
|
|
|
- @this[key] = await addValueFactory();
|
|
|
- }
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
|
|
|
- return @this[key];
|
|
|
+ /// <summary>
|
|
|
+ /// 获取或添加
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key"></param>
|
|
|
+ /// <param name="addValueFactory"></param>
|
|
|
+ public static TValue GetOrAdd<TKey, TValue>(this IDictionary<TKey, TValue> @this, TKey key, Func<TValue> addValueFactory)
|
|
|
+ {
|
|
|
+ if ([email protected](key))
|
|
|
+ {
|
|
|
+ @this[key] = addValueFactory();
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 获取或添加
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TValue"></typeparam>
|
|
|
- /// <param name="this"></param>
|
|
|
- /// <param name="key"></param>
|
|
|
- /// <param name="addValue"></param>
|
|
|
- public static TValue GetOrAdd<TKey, TValue>(this Dictionary<TKey, TValue> @this, TKey key, TValue addValue)
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取或添加
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key"></param>
|
|
|
+ /// <param name="addValueFactory"></param>
|
|
|
+ public static async Task<TValue> GetOrAddAsync<TKey, TValue>(this IDictionary<TKey, TValue> @this, TKey key, Func<Task<TValue>> addValueFactory)
|
|
|
+ {
|
|
|
+ if ([email protected](key))
|
|
|
{
|
|
|
- return @this.TryAdd(key, addValue) ? addValue : @this[key];
|
|
|
+ @this[key] = await addValueFactory();
|
|
|
}
|
|
|
|
|
|
+ return @this[key];
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取或添加
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TValue"></typeparam>
|
|
|
+ /// <param name="this"></param>
|
|
|
+ /// <param name="key"></param>
|
|
|
+ /// <param name="addValue"></param>
|
|
|
+ public static TValue GetOrAdd<TKey, TValue>(this Dictionary<TKey, TValue> @this, TKey key, TValue addValue)
|
|
|
+ {
|
|
|
+ return @this.TryAdd(key, addValue) ? addValue : @this[key];
|
|
|
+ }
|
|
|
+
|
|
|
#if NETSTANDARD2_1_OR_GREATER
|
|
|
#else
|
|
|
|
|
|
- public static bool TryAdd<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value) where TKey : notnull
|
|
|
- {
|
|
|
- if (dictionary == null)
|
|
|
- throw new ArgumentNullException(nameof(dictionary));
|
|
|
- if (dictionary.IsReadOnly||dictionary.ContainsKey(key))
|
|
|
- return false;
|
|
|
- dictionary.Add(key, value);
|
|
|
- return true;
|
|
|
- }
|
|
|
+ public static bool TryAdd<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value) where TKey : notnull
|
|
|
+ {
|
|
|
+ if (dictionary == null)
|
|
|
+ throw new ArgumentNullException(nameof(dictionary));
|
|
|
+ if (dictionary.IsReadOnly || dictionary.ContainsKey(key))
|
|
|
+ return false;
|
|
|
+ dictionary.Add(key, value);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
#endif
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 遍历IEnumerable
|
|
|
- /// </summary>
|
|
|
- /// <param name="dic"></param>
|
|
|
- /// <param name="action">回调方法</param>
|
|
|
- public static void ForEach<TKey, TValue>(this IDictionary<TKey, TValue> dic, Action<TKey, TValue> action)
|
|
|
+ /// <summary>
|
|
|
+ /// 遍历IEnumerable
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dic"></param>
|
|
|
+ /// <param name="action">回调方法</param>
|
|
|
+ public static void ForEach<TKey, TValue>(this IDictionary<TKey, TValue> dic, Action<TKey, TValue> action)
|
|
|
+ {
|
|
|
+ foreach (var item in dic)
|
|
|
{
|
|
|
- foreach (var item in dic)
|
|
|
- {
|
|
|
- action(item.Key, item.Value);
|
|
|
- }
|
|
|
+ action(item.Key, item.Value);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 遍历IDictionary
|
|
|
- /// </summary>
|
|
|
- /// <param name="dic"></param>
|
|
|
- /// <param name="action">回调方法</param>
|
|
|
- public static Task ForEachAsync<TKey, TValue>(this IDictionary<TKey, TValue> dic, Func<TKey, TValue, Task> action)
|
|
|
- {
|
|
|
- return dic.ForeachAsync(x => action(x.Key, x.Value));
|
|
|
- }
|
|
|
+ /// <summary>
|
|
|
+ /// 遍历IDictionary
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dic"></param>
|
|
|
+ /// <param name="action">回调方法</param>
|
|
|
+ public static Task ForEachAsync<TKey, TValue>(this IDictionary<TKey, TValue> dic, Func<TKey, TValue, Task> action)
|
|
|
+ {
|
|
|
+ return dic.ForeachAsync(x => action(x.Key, x.Value));
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- public static NullableDictionary<TKey, TSource> ToDictionarySafety<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ public static NullableDictionary<TKey, TSource> ToDictionarySafety<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
|
|
+ {
|
|
|
+ var items = source as IList<TSource> ?? source.ToList();
|
|
|
+ var dic = new NullableDictionary<TKey, TSource>(items.Count);
|
|
|
+ foreach (var item in items)
|
|
|
{
|
|
|
- var items = source as IList<TSource> ?? source.ToList();
|
|
|
- var dic = new NullableDictionary<TKey, TSource>(items.Count);
|
|
|
- foreach (var item in items)
|
|
|
- {
|
|
|
- dic[keySelector(item)] = item;
|
|
|
- }
|
|
|
-
|
|
|
- return dic;
|
|
|
+ dic[keySelector(item)] = item;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
- public static NullableDictionary<TKey, TSource> ToDictionarySafety<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, TSource defaultValue)
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
+ public static NullableDictionary<TKey, TSource> ToDictionarySafety<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, TSource defaultValue)
|
|
|
+ {
|
|
|
+ var items = source as IList<TSource> ?? source.ToList();
|
|
|
+ var dic = new NullableDictionary<TKey, TSource>(items.Count)
|
|
|
{
|
|
|
- var items = source as IList<TSource> ?? source.ToList();
|
|
|
- var dic = new NullableDictionary<TKey, TSource>(items.Count)
|
|
|
- {
|
|
|
- FallbackValue = defaultValue
|
|
|
- };
|
|
|
- foreach (var item in items)
|
|
|
- {
|
|
|
- dic[keySelector(item)] = item;
|
|
|
- }
|
|
|
-
|
|
|
- return dic;
|
|
|
+ FallbackValue = defaultValue
|
|
|
+ };
|
|
|
+ foreach (var item in items)
|
|
|
+ {
|
|
|
+ dic[keySelector(item)] = item;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TElement"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="elementSelector">值选择器</param>
|
|
|
- public static NullableDictionary<TKey, TElement> ToDictionarySafety<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TElement"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="elementSelector">值选择器</param>
|
|
|
+ public static NullableDictionary<TKey, TElement> ToDictionarySafety<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
|
|
|
+ {
|
|
|
+ var items = source as IList<TSource> ?? source.ToList();
|
|
|
+ var dic = new NullableDictionary<TKey, TElement>(items.Count);
|
|
|
+ foreach (var item in items)
|
|
|
{
|
|
|
- var items = source as IList<TSource> ?? source.ToList();
|
|
|
- var dic = new NullableDictionary<TKey, TElement>(items.Count);
|
|
|
- foreach (var item in items)
|
|
|
- {
|
|
|
- dic[keySelector(item)] = elementSelector(item);
|
|
|
- }
|
|
|
-
|
|
|
- return dic;
|
|
|
+ dic[keySelector(item)] = elementSelector(item);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TElement"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="elementSelector">值选择器</param>
|
|
|
- /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
- public static NullableDictionary<TKey, TElement> ToDictionarySafety<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, TElement defaultValue)
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TElement"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="elementSelector">值选择器</param>
|
|
|
+ /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
+ public static NullableDictionary<TKey, TElement> ToDictionarySafety<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, TElement defaultValue)
|
|
|
+ {
|
|
|
+ var items = source as IList<TSource> ?? source.ToList();
|
|
|
+ var dic = new NullableDictionary<TKey, TElement>(items.Count)
|
|
|
{
|
|
|
- var items = source as IList<TSource> ?? source.ToList();
|
|
|
- var dic = new NullableDictionary<TKey, TElement>(items.Count)
|
|
|
- {
|
|
|
- FallbackValue = defaultValue
|
|
|
- };
|
|
|
- foreach (var item in items)
|
|
|
- {
|
|
|
- dic[keySelector(item)] = elementSelector(item);
|
|
|
- }
|
|
|
-
|
|
|
- return dic;
|
|
|
+ FallbackValue = defaultValue
|
|
|
+ };
|
|
|
+ foreach (var item in items)
|
|
|
+ {
|
|
|
+ dic[keySelector(item)] = elementSelector(item);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TElement"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="elementSelector">值选择器</param>
|
|
|
- public static async Task<NullableDictionary<TKey, TElement>> ToDictionarySafetyAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector)
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TElement"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="elementSelector">值选择器</param>
|
|
|
+ public static async Task<NullableDictionary<TKey, TElement>> ToDictionarySafetyAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector)
|
|
|
+ {
|
|
|
+ var items = source as IList<TSource> ?? source.ToList();
|
|
|
+ var dic = new NullableDictionary<TKey, TElement>(items.Count);
|
|
|
+ await items.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TElement"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="elementSelector">值选择器</param>
|
|
|
+ /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
+ public static async Task<NullableDictionary<TKey, TElement>> ToDictionarySafetyAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector, TElement defaultValue)
|
|
|
+ {
|
|
|
+ var items = source as IList<TSource> ?? source.ToList();
|
|
|
+ var dic = new NullableDictionary<TKey, TElement>(items.Count)
|
|
|
{
|
|
|
- var items = source as IList<TSource> ?? source.ToList();
|
|
|
- var dic = new NullableDictionary<TKey, TElement>(items.Count);
|
|
|
- await items.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
|
|
|
- return dic;
|
|
|
- }
|
|
|
+ FallbackValue = defaultValue
|
|
|
+ };
|
|
|
+ await items.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TElement"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="elementSelector">值选择器</param>
|
|
|
- /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
- public static async Task<NullableDictionary<TKey, TElement>> ToDictionarySafetyAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector, TElement defaultValue)
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ public static DisposableDictionary<TKey, TSource> ToDisposableDictionarySafety<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) where TSource : IDisposable
|
|
|
+ {
|
|
|
+ var items = source as IList<TSource> ?? source.ToList();
|
|
|
+ var dic = new DisposableDictionary<TKey, TSource>(items.Count);
|
|
|
+ foreach (var item in items)
|
|
|
{
|
|
|
- var items = source as IList<TSource> ?? source.ToList();
|
|
|
- var dic = new NullableDictionary<TKey, TElement>(items.Count)
|
|
|
- {
|
|
|
- FallbackValue = defaultValue
|
|
|
- };
|
|
|
- await items.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
|
|
|
- return dic;
|
|
|
+ dic[keySelector(item)] = item;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- public static DisposableDictionary<TKey, TSource> ToDisposableDictionarySafety<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) where TSource : IDisposable
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
+ public static DisposableDictionary<TKey, TSource> ToDisposableDictionarySafety<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, TSource defaultValue) where TSource : IDisposable
|
|
|
+ {
|
|
|
+ var items = source as IList<TSource> ?? source.ToList();
|
|
|
+ var dic = new DisposableDictionary<TKey, TSource>(items.Count)
|
|
|
+ {
|
|
|
+ FallbackValue = defaultValue
|
|
|
+ };
|
|
|
+ foreach (var item in items)
|
|
|
{
|
|
|
- var items = source as IList<TSource> ?? source.ToList();
|
|
|
- var dic = new DisposableDictionary<TKey, TSource>(items.Count);
|
|
|
- foreach (var item in items)
|
|
|
- {
|
|
|
- dic[keySelector(item)] = item;
|
|
|
- }
|
|
|
-
|
|
|
- return dic;
|
|
|
+ dic[keySelector(item)] = item;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
- public static DisposableDictionary<TKey, TSource> ToDisposableDictionarySafety<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, TSource defaultValue) where TSource : IDisposable
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TElement"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="elementSelector">值选择器</param>
|
|
|
+ public static DisposableDictionary<TKey, TElement> ToDisposableDictionarySafety<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) where TElement : IDisposable
|
|
|
+ {
|
|
|
+ var items = source as IList<TSource> ?? source.ToList();
|
|
|
+ var dic = new DisposableDictionary<TKey, TElement>(items.Count);
|
|
|
+ foreach (var item in items)
|
|
|
{
|
|
|
- var items = source as IList<TSource> ?? source.ToList();
|
|
|
- var dic = new DisposableDictionary<TKey, TSource>(items.Count)
|
|
|
- {
|
|
|
- FallbackValue = defaultValue
|
|
|
- };
|
|
|
- foreach (var item in items)
|
|
|
- {
|
|
|
- dic[keySelector(item)] = item;
|
|
|
- }
|
|
|
-
|
|
|
- return dic;
|
|
|
+ dic[keySelector(item)] = elementSelector(item);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TElement"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="elementSelector">值选择器</param>
|
|
|
- public static DisposableDictionary<TKey, TElement> ToDisposableDictionarySafety<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) where TElement : IDisposable
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TElement"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="elementSelector">值选择器</param>
|
|
|
+ /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
+ public static DisposableDictionary<TKey, TElement> ToDisposableDictionarySafety<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, TElement defaultValue) where TElement : IDisposable
|
|
|
+ {
|
|
|
+ var items = source as IList<TSource> ?? source.ToList();
|
|
|
+ var dic = new DisposableDictionary<TKey, TElement>(items.Count)
|
|
|
+ {
|
|
|
+ FallbackValue = defaultValue
|
|
|
+ };
|
|
|
+ foreach (var item in items)
|
|
|
{
|
|
|
- var items = source as IList<TSource> ?? source.ToList();
|
|
|
- var dic = new DisposableDictionary<TKey, TElement>(items.Count);
|
|
|
- foreach (var item in items)
|
|
|
- {
|
|
|
- dic[keySelector(item)] = elementSelector(item);
|
|
|
- }
|
|
|
-
|
|
|
- return dic;
|
|
|
+ dic[keySelector(item)] = elementSelector(item);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TElement"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="elementSelector">值选择器</param>
|
|
|
- /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
- public static DisposableDictionary<TKey, TElement> ToDisposableDictionarySafety<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, TElement defaultValue) where TElement : IDisposable
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TElement"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="elementSelector">值选择器</param>
|
|
|
+ public static async Task<DisposableDictionary<TKey, TElement>> ToDisposableDictionarySafetyAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector) where TElement : IDisposable
|
|
|
+ {
|
|
|
+ var items = source as IList<TSource> ?? source.ToList();
|
|
|
+ var dic = new DisposableDictionary<TKey, TElement>(items.Count);
|
|
|
+ await items.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TElement"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="elementSelector">值选择器</param>
|
|
|
+ /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
+ public static async Task<DisposableDictionary<TKey, TElement>> ToDisposableDictionarySafetyAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector, TElement defaultValue) where TElement : IDisposable
|
|
|
+ {
|
|
|
+ var items = source as IList<TSource> ?? source.ToList();
|
|
|
+ var dic = new DisposableDictionary<TKey, TElement>(items.Count)
|
|
|
{
|
|
|
- var items = source as IList<TSource> ?? source.ToList();
|
|
|
- var dic = new DisposableDictionary<TKey, TElement>(items.Count)
|
|
|
- {
|
|
|
- FallbackValue = defaultValue
|
|
|
- };
|
|
|
- foreach (var item in items)
|
|
|
- {
|
|
|
- dic[keySelector(item)] = elementSelector(item);
|
|
|
- }
|
|
|
-
|
|
|
- return dic;
|
|
|
- }
|
|
|
+ FallbackValue = defaultValue
|
|
|
+ };
|
|
|
+ await items.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TElement"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="elementSelector">值选择器</param>
|
|
|
- public static async Task<DisposableDictionary<TKey, TElement>> ToDisposableDictionarySafetyAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector) where TElement : IDisposable
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ public static NullableConcurrentDictionary<TKey, TSource> ToConcurrentDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
|
|
+ {
|
|
|
+ var dic = new NullableConcurrentDictionary<TKey, TSource>();
|
|
|
+ foreach (var item in source)
|
|
|
{
|
|
|
- var items = source as IList<TSource> ?? source.ToList();
|
|
|
- var dic = new DisposableDictionary<TKey, TElement>(items.Count);
|
|
|
- await items.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
|
|
|
- return dic;
|
|
|
+ dic[keySelector(item)] = item;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TElement"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="elementSelector">值选择器</param>
|
|
|
- /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
- public static async Task<DisposableDictionary<TKey, TElement>> ToDisposableDictionarySafetyAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector, TElement defaultValue) where TElement : IDisposable
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
+ public static NullableConcurrentDictionary<TKey, TSource> ToConcurrentDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, TSource defaultValue)
|
|
|
+ {
|
|
|
+ var dic = new NullableConcurrentDictionary<TKey, TSource>()
|
|
|
+ {
|
|
|
+ FallbackValue = defaultValue
|
|
|
+ };
|
|
|
+ foreach (var item in source)
|
|
|
{
|
|
|
- var items = source as IList<TSource> ?? source.ToList();
|
|
|
- var dic = new DisposableDictionary<TKey, TElement>(items.Count)
|
|
|
- {
|
|
|
- FallbackValue = defaultValue
|
|
|
- };
|
|
|
- await items.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
|
|
|
- return dic;
|
|
|
+ dic[keySelector(item)] = item;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- public static NullableConcurrentDictionary<TKey, TSource> ToConcurrentDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
|
|
- {
|
|
|
- var dic = new NullableConcurrentDictionary<TKey, TSource>();
|
|
|
- foreach (var item in source)
|
|
|
- {
|
|
|
- dic[keySelector(item)] = item;
|
|
|
- }
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
|
|
|
- return dic;
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TElement"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="elementSelector">值选择器</param>
|
|
|
+ public static NullableConcurrentDictionary<TKey, TElement> ToConcurrentDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
|
|
|
+ {
|
|
|
+ var dic = new NullableConcurrentDictionary<TKey, TElement>();
|
|
|
+ foreach (var item in source)
|
|
|
+ {
|
|
|
+ dic[keySelector(item)] = elementSelector(item);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
- public static NullableConcurrentDictionary<TKey, TSource> ToConcurrentDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, TSource defaultValue)
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TElement"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="elementSelector">值选择器</param>
|
|
|
+ /// <param name="defaultValue"></param>
|
|
|
+ public static NullableConcurrentDictionary<TKey, TElement> ToConcurrentDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, TElement defaultValue)
|
|
|
+ {
|
|
|
+ var dic = new NullableConcurrentDictionary<TKey, TElement>()
|
|
|
{
|
|
|
- var dic = new NullableConcurrentDictionary<TKey, TSource>()
|
|
|
- {
|
|
|
- FallbackValue = defaultValue
|
|
|
- };
|
|
|
- foreach (var item in source)
|
|
|
- {
|
|
|
- dic[keySelector(item)] = item;
|
|
|
- }
|
|
|
-
|
|
|
- return dic;
|
|
|
+ FallbackValue = defaultValue
|
|
|
+ };
|
|
|
+ foreach (var item in source)
|
|
|
+ {
|
|
|
+ dic[keySelector(item)] = elementSelector(item);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TElement"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="elementSelector">值选择器</param>
|
|
|
- public static NullableConcurrentDictionary<TKey, TElement> ToConcurrentDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
|
|
|
- {
|
|
|
- var dic = new NullableConcurrentDictionary<TKey, TElement>();
|
|
|
- foreach (var item in source)
|
|
|
- {
|
|
|
- dic[keySelector(item)] = elementSelector(item);
|
|
|
- }
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
|
|
|
- return dic;
|
|
|
- }
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TElement"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="elementSelector">值选择器</param>
|
|
|
+ public static async Task<NullableConcurrentDictionary<TKey, TElement>> ToConcurrentDictionaryAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector)
|
|
|
+ {
|
|
|
+ var dic = new ConcurrentDictionary<TKey, TElement>();
|
|
|
+ await source.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TElement"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="elementSelector">值选择器</param>
|
|
|
- /// <param name="defaultValue"></param>
|
|
|
- public static NullableConcurrentDictionary<TKey, TElement> ToConcurrentDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, TElement defaultValue)
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <typeparam name="TElement"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="elementSelector">值选择器</param>
|
|
|
+ /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
+ public static async Task<NullableConcurrentDictionary<TKey, TElement>> ToConcurrentDictionaryAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector, TElement defaultValue)
|
|
|
+ {
|
|
|
+ var dic = new NullableConcurrentDictionary<TKey, TElement>
|
|
|
{
|
|
|
- var dic = new NullableConcurrentDictionary<TKey, TElement>()
|
|
|
- {
|
|
|
- FallbackValue = defaultValue
|
|
|
- };
|
|
|
- foreach (var item in source)
|
|
|
- {
|
|
|
- dic[keySelector(item)] = elementSelector(item);
|
|
|
- }
|
|
|
-
|
|
|
- return dic;
|
|
|
- }
|
|
|
+ FallbackValue = defaultValue
|
|
|
+ };
|
|
|
+ await source.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TElement"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="elementSelector">值选择器</param>
|
|
|
- public static async Task<NullableConcurrentDictionary<TKey, TElement>> ToConcurrentDictionaryAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector)
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TSource"></typeparam>
|
|
|
+ /// <typeparam name="TKey"></typeparam>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ public static DisposableConcurrentDictionary<TKey, TSource> ToDisposableConcurrentDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) where TSource : IDisposable
|
|
|
+ {
|
|
|
+ var dic = new DisposableConcurrentDictionary<TKey, TSource>();
|
|
|
+ foreach (var item in source)
|
|
|
{
|
|
|
- var dic = new ConcurrentDictionary<TKey, TElement>();
|
|
|
- await source.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
|
|
|
- return dic;
|
|
|
+ dic[keySelector(item)] = item;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <typeparam name="TElement"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="elementSelector">值选择器</param>
|
|
|
- /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
- public static async Task<NullableConcurrentDictionary<TKey, TElement>> ToConcurrentDictionaryAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector, TElement defaultValue)
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
+ public static DisposableConcurrentDictionary<TKey, TSource> ToDisposableConcurrentDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, TSource defaultValue) where TSource : IDisposable
|
|
|
+ {
|
|
|
+ var dic = new DisposableConcurrentDictionary<TKey, TSource>
|
|
|
+ {
|
|
|
+ FallbackValue = defaultValue
|
|
|
+ };
|
|
|
+ foreach (var item in source)
|
|
|
{
|
|
|
- var dic = new NullableConcurrentDictionary<TKey, TElement>
|
|
|
- {
|
|
|
- FallbackValue = defaultValue
|
|
|
- };
|
|
|
- await source.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
|
|
|
- return dic;
|
|
|
+ dic[keySelector(item)] = item;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TSource"></typeparam>
|
|
|
- /// <typeparam name="TKey"></typeparam>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- public static DisposableConcurrentDictionary<TKey, TSource> ToDisposableConcurrentDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) where TSource : IDisposable
|
|
|
- {
|
|
|
- var dic = new DisposableConcurrentDictionary<TKey, TSource>();
|
|
|
- foreach (var item in source)
|
|
|
- {
|
|
|
- dic[keySelector(item)] = item;
|
|
|
- }
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
|
|
|
- return dic;
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="elementSelector">值选择器</param>
|
|
|
+ public static DisposableConcurrentDictionary<TKey, TElement> ToDisposableConcurrentDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) where TElement : IDisposable
|
|
|
+ {
|
|
|
+ var dic = new DisposableConcurrentDictionary<TKey, TElement>();
|
|
|
+ foreach (var item in source)
|
|
|
+ {
|
|
|
+ dic[keySelector(item)] = elementSelector(item);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
- public static DisposableConcurrentDictionary<TKey, TSource> ToDisposableConcurrentDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, TSource defaultValue) where TSource : IDisposable
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="elementSelector">值选择器</param>
|
|
|
+ /// <param name="defaultValue"></param>
|
|
|
+ public static DisposableConcurrentDictionary<TKey, TElement> ToDisposableConcurrentDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, TElement defaultValue) where TElement : IDisposable
|
|
|
+ {
|
|
|
+ var dic = new DisposableConcurrentDictionary<TKey, TElement>()
|
|
|
{
|
|
|
- var dic = new DisposableConcurrentDictionary<TKey, TSource>
|
|
|
- {
|
|
|
- FallbackValue = defaultValue
|
|
|
- };
|
|
|
- foreach (var item in source)
|
|
|
- {
|
|
|
- dic[keySelector(item)] = item;
|
|
|
- }
|
|
|
-
|
|
|
- return dic;
|
|
|
+ FallbackValue = defaultValue
|
|
|
+ };
|
|
|
+ foreach (var item in source)
|
|
|
+ {
|
|
|
+ dic[keySelector(item)] = elementSelector(item);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="elementSelector">值选择器</param>
|
|
|
- public static DisposableConcurrentDictionary<TKey, TElement> ToDisposableConcurrentDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) where TElement : IDisposable
|
|
|
- {
|
|
|
- var dic = new DisposableConcurrentDictionary<TKey, TElement>();
|
|
|
- foreach (var item in source)
|
|
|
- {
|
|
|
- dic[keySelector(item)] = elementSelector(item);
|
|
|
- }
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
|
|
|
- return dic;
|
|
|
- }
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="elementSelector">值选择器</param>
|
|
|
+ public static async Task<DisposableConcurrentDictionary<TKey, TElement>> ToDisposableConcurrentDictionaryAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector) where TElement : IDisposable
|
|
|
+ {
|
|
|
+ var dic = new DisposableConcurrentDictionary<TKey, TElement>();
|
|
|
+ await source.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="elementSelector">值选择器</param>
|
|
|
- /// <param name="defaultValue"></param>
|
|
|
- public static DisposableConcurrentDictionary<TKey, TElement> ToDisposableConcurrentDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, TElement defaultValue) where TElement : IDisposable
|
|
|
+ /// <summary>
|
|
|
+ /// 安全的转换成字典集
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="keySelector">键选择器</param>
|
|
|
+ /// <param name="elementSelector">值选择器</param>
|
|
|
+ /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
+ public static async Task<DisposableConcurrentDictionary<TKey, TElement>> ToDisposableConcurrentDictionaryAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector, TElement defaultValue) where TElement : IDisposable
|
|
|
+ {
|
|
|
+ var dic = new DisposableConcurrentDictionary<TKey, TElement>()
|
|
|
{
|
|
|
- var dic = new DisposableConcurrentDictionary<TKey, TElement>()
|
|
|
- {
|
|
|
- FallbackValue = defaultValue
|
|
|
- };
|
|
|
- foreach (var item in source)
|
|
|
- {
|
|
|
- dic[keySelector(item)] = elementSelector(item);
|
|
|
- }
|
|
|
-
|
|
|
- return dic;
|
|
|
- }
|
|
|
+ FallbackValue = defaultValue
|
|
|
+ };
|
|
|
+ await source.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="elementSelector">值选择器</param>
|
|
|
- public static async Task<DisposableConcurrentDictionary<TKey, TElement>> ToDisposableConcurrentDictionaryAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector) where TElement : IDisposable
|
|
|
+ /// <summary>
|
|
|
+ /// 转换成并发字典集合
|
|
|
+ /// </summary>
|
|
|
+ public static NullableConcurrentDictionary<TKey, TValue> AsConcurrentDictionary<TKey, TValue>(this Dictionary<TKey, TValue> dic) => dic;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 转换成并发字典集合
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dic"></param>
|
|
|
+ /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
+ public static NullableConcurrentDictionary<TKey, TValue> AsConcurrentDictionary<TKey, TValue>(this Dictionary<TKey, TValue> dic, TValue defaultValue)
|
|
|
+ {
|
|
|
+ var nullableDictionary = new NullableConcurrentDictionary<TKey, TValue>()
|
|
|
{
|
|
|
- var dic = new DisposableConcurrentDictionary<TKey, TElement>();
|
|
|
- await source.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
|
|
|
- return dic;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 安全的转换成字典集
|
|
|
- /// </summary>
|
|
|
- /// <param name="source"></param>
|
|
|
- /// <param name="keySelector">键选择器</param>
|
|
|
- /// <param name="elementSelector">值选择器</param>
|
|
|
- /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
- public static async Task<DisposableConcurrentDictionary<TKey, TElement>> ToDisposableConcurrentDictionaryAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector, TElement defaultValue) where TElement : IDisposable
|
|
|
+ FallbackValue = defaultValue
|
|
|
+ };
|
|
|
+ foreach (var p in dic)
|
|
|
{
|
|
|
- var dic = new DisposableConcurrentDictionary<TKey, TElement>()
|
|
|
- {
|
|
|
- FallbackValue = defaultValue
|
|
|
- };
|
|
|
- await source.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
|
|
|
- return dic;
|
|
|
+ nullableDictionary[p.Key] = p.Value;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 转换成并发字典集合
|
|
|
- /// </summary>
|
|
|
- public static NullableConcurrentDictionary<TKey, TValue> AsConcurrentDictionary<TKey, TValue>(this Dictionary<TKey, TValue> dic) => dic;
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 转换成并发字典集合
|
|
|
- /// </summary>
|
|
|
- /// <param name="dic"></param>
|
|
|
- /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
- public static NullableConcurrentDictionary<TKey, TValue> AsConcurrentDictionary<TKey, TValue>(this Dictionary<TKey, TValue> dic, TValue defaultValue)
|
|
|
- {
|
|
|
- var nullableDictionary = new NullableConcurrentDictionary<TKey, TValue>()
|
|
|
- {
|
|
|
- FallbackValue = defaultValue
|
|
|
- };
|
|
|
- foreach (var p in dic)
|
|
|
- {
|
|
|
- nullableDictionary[p.Key] = p.Value;
|
|
|
- }
|
|
|
-
|
|
|
- return nullableDictionary;
|
|
|
- }
|
|
|
+ return nullableDictionary;
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 转换成普通字典集合
|
|
|
- /// </summary>
|
|
|
- public static NullableDictionary<TKey, TValue> AsDictionary<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dic) => dic;
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 转换成普通字典集合
|
|
|
- /// </summary>
|
|
|
- /// <param name="dic"></param>
|
|
|
- /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
- public static NullableDictionary<TKey, TValue> AsDictionary<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dic, TValue defaultValue)
|
|
|
+ /// <summary>
|
|
|
+ /// 转换成普通字典集合
|
|
|
+ /// </summary>
|
|
|
+ public static NullableDictionary<TKey, TValue> AsDictionary<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dic) => dic;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 转换成普通字典集合
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dic"></param>
|
|
|
+ /// <param name="defaultValue">键未找到时的默认值</param>
|
|
|
+ public static NullableDictionary<TKey, TValue> AsDictionary<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dic, TValue defaultValue)
|
|
|
+ {
|
|
|
+ var nullableDictionary = new NullableDictionary<TKey, TValue>()
|
|
|
+ {
|
|
|
+ FallbackValue = defaultValue
|
|
|
+ };
|
|
|
+ foreach (var p in dic)
|
|
|
{
|
|
|
- var nullableDictionary = new NullableDictionary<TKey, TValue>()
|
|
|
- {
|
|
|
- FallbackValue = defaultValue
|
|
|
- };
|
|
|
- foreach (var p in dic)
|
|
|
- {
|
|
|
- nullableDictionary[p.Key] = p.Value;
|
|
|
- }
|
|
|
-
|
|
|
- return nullableDictionary;
|
|
|
+ nullableDictionary[p.Key] = p.Value;
|
|
|
}
|
|
|
+
|
|
|
+ return nullableDictionary;
|
|
|
}
|
|
|
}
|