消除部分warning
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public static class EnumExtensions
|
||||
/// <returns></returns>
|
||||
public static string GetDescription(this System.Enum value)
|
||||
{
|
||||
return value.GetType().GetMember(value.ToString()).FirstOrDefault()?.GetCustomAttribute<DescriptionAttribute>()?.Description;
|
||||
return value.GetType().GetMember(value.ToString()).FirstOrDefault()?.GetCustomAttribute<DescriptionAttribute>()?.Description ?? string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -162,7 +162,7 @@ public static class EnumExtensions
|
||||
/// <returns></returns>
|
||||
public static string GetDescription(this object value)
|
||||
{
|
||||
return value.GetType().GetMember(value.ToString() ?? string.Empty).FirstOrDefault()?.GetCustomAttribute<DescriptionAttribute>()?.Description;
|
||||
return value.GetType().GetMember(value.ToString() ?? string.Empty).FirstOrDefault()?.GetCustomAttribute<DescriptionAttribute>()?.Description ?? string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -219,7 +219,7 @@ public static partial class Extensions
|
||||
/// </summary>
|
||||
private static bool? GetBool(this object data)
|
||||
{
|
||||
switch (data.ToString().Trim().ToLower())
|
||||
switch (data.ToString()?.Trim().ToLower())
|
||||
{
|
||||
case "0":
|
||||
return false;
|
||||
@@ -466,7 +466,7 @@ public static partial class Extensions
|
||||
{
|
||||
try
|
||||
{
|
||||
return obj == null ? string.Empty : obj.ToString();
|
||||
return obj == null ? string.Empty : obj.ToString()!;
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -489,7 +489,7 @@ public static partial class Extensions
|
||||
return string.Join(",", list);
|
||||
}
|
||||
|
||||
return obj.ToString();
|
||||
return obj.ToString()!;
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -678,7 +678,7 @@ public static partial class Extensions
|
||||
/// <returns></returns>
|
||||
public static string ObjToString(this object thisValue)
|
||||
{
|
||||
if (thisValue != null) return thisValue.ToString().Trim();
|
||||
if (thisValue != null) return thisValue.ToString()!.Trim();
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public static class RandomExtensions
|
||||
|
||||
Array array = System.Enum.GetValues(type);
|
||||
int index = random.Next(array.GetLowerBound(0), array.GetUpperBound(0) + 1);
|
||||
return (T)array.GetValue(index);
|
||||
return (T)array.GetValue(index)!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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)];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user