mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-09-06 05:36:53 +00:00
chore: Fix compilation warning messages.
This commit is contained in:
@@ -15,7 +15,7 @@ namespace ZonyLrcTools.Common.Infrastructure.DependencyInject
|
||||
/// <summary>
|
||||
/// 配置工具会用到的服务。
|
||||
/// </summary>
|
||||
public static IServiceCollection ConfigureToolService(this IServiceCollection services)
|
||||
public static IServiceCollection? ConfigureToolService(this IServiceCollection? services)
|
||||
{
|
||||
if (services == null)
|
||||
{
|
||||
|
@@ -7,7 +7,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Exceptions
|
||||
{
|
||||
public int ErrorCode { get; }
|
||||
|
||||
public object AttachObject { get; }
|
||||
public object? AttachObject { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 构建一个新的 <see cref="ErrorCodeException"/> 对象。
|
||||
@@ -15,7 +15,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Exceptions
|
||||
/// <param name="errorCode">错误码,参考 <see cref="ErrorCodes"/> 类的定义。</param>
|
||||
/// <param name="message">错误信息。</param>
|
||||
/// <param name="attachObj">附加的对象数据。</param>
|
||||
public ErrorCodeException(int errorCode, string? message = null, object attachObj = null) : base(message)
|
||||
public ErrorCodeException(int errorCode, string? message = null, object? attachObj = null) : base(message)
|
||||
{
|
||||
ErrorCode = errorCode;
|
||||
AttachObject = attachObj;
|
||||
|
@@ -33,7 +33,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Exceptions
|
||||
var errors = jsonObj.SelectTokens("$.Error.*");
|
||||
var warnings = jsonObj.SelectTokens("$.Warning.*");
|
||||
errors.Union(warnings).Select(m => m.Parent).OfType<JProperty>().ToList()
|
||||
.ForEach(m => ErrorMessages.Add(int.Parse(m.Name), m.Value.Value<string>()));
|
||||
.ForEach(m => ErrorMessages.Add(int.Parse(m.Name), m.Value.Value<string>() ?? string.Empty));
|
||||
}
|
||||
|
||||
public static string GetMessage(int errorCode) => ErrorMessages[errorCode];
|
||||
|
@@ -17,7 +17,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Extensions
|
||||
/// <param name="logger">日志记录器实例。</param>
|
||||
/// <param name="errorCode">错误码,具体请参考 <see cref="ErrorCodes"/> 类的定义。</param>
|
||||
/// <param name="e">异常实例,可为空。</param>
|
||||
public static void LogWarningWithErrorCode(this IWarpLogger logger, int errorCode, Exception e = null)
|
||||
public static void LogWarningWithErrorCode(this IWarpLogger logger, int errorCode, Exception? e = null)
|
||||
{
|
||||
logger.WarnAsync($"错误代码: {errorCode}\n堆栈异常: {e?.StackTrace}").GetAwaiter().GetResult();
|
||||
}
|
||||
|
@@ -19,9 +19,9 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
|
||||
}
|
||||
|
||||
public async ValueTask<string> PostAsync(string url,
|
||||
object parameters = null,
|
||||
object? parameters = null,
|
||||
bool isQueryStringParam = false,
|
||||
Action<HttpRequestMessage> requestOption = null)
|
||||
Action<HttpRequestMessage>? requestOption = null)
|
||||
{
|
||||
using var responseMessage = await PostReturnHttpResponseAsync(url, parameters, isQueryStringParam, requestOption);
|
||||
var responseContentString = await responseMessage.Content.ReadAsStringAsync();
|
||||
@@ -30,18 +30,18 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
|
||||
}
|
||||
|
||||
public async ValueTask<TResponse> PostAsync<TResponse>(string url,
|
||||
object parameters = null,
|
||||
object? parameters = null,
|
||||
bool isQueryStringParam = false,
|
||||
Action<HttpRequestMessage> requestOption = null)
|
||||
Action<HttpRequestMessage>? requestOption = null)
|
||||
{
|
||||
var responseString = await PostAsync(url, parameters, isQueryStringParam, requestOption);
|
||||
return ConvertHttpResponseToObject<TResponse>(parameters, responseString);
|
||||
}
|
||||
|
||||
public async ValueTask<HttpResponseMessage> PostReturnHttpResponseAsync(string url,
|
||||
object parameters = null,
|
||||
object? parameters = null,
|
||||
bool isQueryStringParam = false,
|
||||
Action<HttpRequestMessage> requestOption = null)
|
||||
Action<HttpRequestMessage>? requestOption = null)
|
||||
{
|
||||
var parametersStr = isQueryStringParam ? BuildQueryString(parameters) : BuildJsonBodyString(parameters);
|
||||
var requestMessage = new HttpRequestMessage(HttpMethod.Post, new Uri(url));
|
||||
@@ -53,8 +53,8 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
|
||||
}
|
||||
|
||||
public async ValueTask<string> GetAsync(string url,
|
||||
object parameters = null,
|
||||
Action<HttpRequestMessage> requestOption = null)
|
||||
object? parameters = null,
|
||||
Action<HttpRequestMessage>? requestOption = null)
|
||||
{
|
||||
var requestParamsStr = BuildQueryString(parameters);
|
||||
var requestMsg = new HttpRequestMessage(HttpMethod.Get, new Uri($"{url}?{requestParamsStr}"));
|
||||
@@ -67,8 +67,8 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
|
||||
}
|
||||
|
||||
public async ValueTask<TResponse> GetAsync<TResponse>(string url,
|
||||
object parameters = null,
|
||||
Action<HttpRequestMessage> requestOption = null)
|
||||
object? parameters = null,
|
||||
Action<HttpRequestMessage>? requestOption = null)
|
||||
{
|
||||
var responseString = await GetAsync(url, parameters, requestOption);
|
||||
return ConvertHttpResponseToObject<TResponse>(parameters, responseString);
|
||||
@@ -79,7 +79,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
|
||||
return _httpClientFactory.CreateClient(HttpClientNameConstant);
|
||||
}
|
||||
|
||||
private string BuildQueryString(object parameters)
|
||||
private string BuildQueryString(object? parameters)
|
||||
{
|
||||
if (parameters == null)
|
||||
{
|
||||
@@ -89,7 +89,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
|
||||
var type = parameters.GetType();
|
||||
if (type == typeof(string))
|
||||
{
|
||||
return parameters as string;
|
||||
return parameters as string ?? string.Empty;
|
||||
}
|
||||
|
||||
var properties = type.GetProperties();
|
||||
@@ -106,7 +106,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
|
||||
return paramBuilder.ToString().TrimEnd('&');
|
||||
}
|
||||
|
||||
private string BuildJsonBodyString(object parameters)
|
||||
private string BuildJsonBodyString(object? parameters)
|
||||
{
|
||||
if (parameters == null) return string.Empty;
|
||||
if (parameters is string result) return result;
|
||||
@@ -122,7 +122,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
|
||||
/// <param name="responseString">执行 Http 请求之后响应内容。</param>
|
||||
/// <returns>如果响应正常,则返回具体的响应内容。</returns>
|
||||
/// <exception cref="ErrorCodeException">如果 Http 响应不正常,则可能抛出本异常。</exception>
|
||||
private string ValidateHttpResponse(HttpResponseMessage responseMessage, object requestParameters, string responseString)
|
||||
private string ValidateHttpResponse(HttpResponseMessage responseMessage, object? requestParameters, string responseString)
|
||||
{
|
||||
return responseMessage.StatusCode switch
|
||||
{
|
||||
@@ -139,7 +139,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
|
||||
/// <param name="responseString">执行 Http 请求之后响应内容。</param>
|
||||
/// <typeparam name="TResponse">需要将响应结果反序列化的目标类型。</typeparam>
|
||||
/// <exception cref="ErrorCodeException">如果反序列化失败,则可能抛出本异常。</exception>
|
||||
private TResponse ConvertHttpResponseToObject<TResponse>(object requestParameters, string responseString)
|
||||
private TResponse ConvertHttpResponseToObject<TResponse>(object? requestParameters, string responseString)
|
||||
{
|
||||
var throwException = new ErrorCodeException(ErrorCodes.HttpResponseConvertJsonFailed, attachObj: new { requestParameters, responseString });
|
||||
|
||||
|
@@ -14,9 +14,9 @@
|
||||
/// <param name="requestOption">请求时的配置动作。</param>
|
||||
/// <returns>服务端的响应结果。</returns>
|
||||
ValueTask<string> PostAsync(string url,
|
||||
object parameters = null,
|
||||
object? parameters = null,
|
||||
bool isQueryStringParam = false,
|
||||
Action<HttpRequestMessage> requestOption = null);
|
||||
Action<HttpRequestMessage>? requestOption = null);
|
||||
|
||||
/// <summary>
|
||||
/// 根据指定的配置执行 POST 请求,并将结果反序列化为 <see cref="TResponse"/> 对象。
|
||||
@@ -28,14 +28,14 @@
|
||||
/// <typeparam name="TResponse">需要将响应结果反序列化的目标类型。</typeparam>
|
||||
/// <returns>服务端的响应结果。</returns>
|
||||
ValueTask<TResponse> PostAsync<TResponse>(string url,
|
||||
object parameters = null,
|
||||
object? parameters = null,
|
||||
bool isQueryStringParam = false,
|
||||
Action<HttpRequestMessage> requestOption = null);
|
||||
Action<HttpRequestMessage>? requestOption = null);
|
||||
|
||||
ValueTask<HttpResponseMessage> PostReturnHttpResponseAsync(string url,
|
||||
object parameters = null,
|
||||
object? parameters = null,
|
||||
bool isQueryStringParam = false,
|
||||
Action<HttpRequestMessage> requestOption = null);
|
||||
Action<HttpRequestMessage>? requestOption = null);
|
||||
|
||||
/// <summary>
|
||||
/// 根据指定的配置执行 GET 请求,并以 <see cref="string"/> 作为返回值。
|
||||
@@ -45,8 +45,8 @@
|
||||
/// <param name="requestOption">请求时的配置动作。</param>
|
||||
/// <returns>服务端的响应结果。</returns>
|
||||
ValueTask<string> GetAsync(string url,
|
||||
object parameters = null,
|
||||
Action<HttpRequestMessage> requestOption = null);
|
||||
object? parameters = null,
|
||||
Action<HttpRequestMessage>? requestOption = null);
|
||||
|
||||
/// <summary>
|
||||
/// 根据指定的配置执行 GET 请求,并将结果反序列化为 <see cref="TResponse"/> 对象。
|
||||
@@ -58,7 +58,7 @@
|
||||
/// <returns>服务端的响应结果。</returns>
|
||||
ValueTask<TResponse> GetAsync<TResponse>(
|
||||
string url,
|
||||
object parameters = null,
|
||||
Action<HttpRequestMessage> requestOption = null);
|
||||
object? parameters = null,
|
||||
Action<HttpRequestMessage>? requestOption = null);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user