This commit is contained in:
2023-05-31 10:19:05 +08:00
parent 1b65a7a9e5
commit 9c621c75cd
238 changed files with 9905 additions and 4034 deletions

View File

@@ -31,7 +31,7 @@ public static class BooleanExtensions
/// </summary>
private static bool? GetBool(this object data)
{
switch (data.ToString()?.Trim().ToLower())
switch (data.ToString().Trim().ToLower())
{
case "0":
return false;

View File

@@ -16,7 +16,7 @@ public static class DictionaryExtensions
/// <param name="dictionary">要操作的字典.</param>
/// <param name="key">指定键名.</param>
/// <returns>获取到的值.</returns>
public static TValue? GetOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
public static TValue GetOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
{
return dictionary.TryGetValue(key, out TValue value) ? value : default(TValue);
}

View File

@@ -693,4 +693,25 @@ public static partial class Extensions
}
#endregion
#region List
/// <summary>
/// 嵌套List解析
/// 仅限于列表查询条件多选.
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public static List<string> ParseToNestedList(this List<List<string>> list)
{
List<string> result = new List<string>();
if (list != null && list.Count > 0)
{
foreach (var item in list)
result.Add(item.Last());
}
return result;
}
#endregion
}

View File

@@ -67,7 +67,7 @@ public static class RandomExtensions
public static T NextItem<T>(this Random random, T[] items)
{
if (items == null || items.Length == 0)
return default(T)!;
return default(T);
return items[random.Next(items.Length)];
}

View File

@@ -354,7 +354,7 @@ public static class StringExtensions
/// 指示指定的字符串是 null、空或者仅由空白字符组成.
/// </summary>
[DebuggerStepThrough]
public static bool IsNullOrWhiteSpace(this string value)
public static bool IsNullOrWhiteSpace(this string? value)
{
return string.IsNullOrWhiteSpace(value);
}