From eac0c84e11bbea6aa50bab51ea72ca5b9cf20db9 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 23 Mar 2024 18:26:04 +0800 Subject: [PATCH] Improve IsNullOrEmpty --- v2rayN/v2rayN/Common/DownloaderHelper.cs | 8 ++++---- v2rayN/v2rayN/Common/HttpClientHelper.cs | 6 +++--- v2rayN/v2rayN/Common/JsonUtile.cs | 4 ++-- v2rayN/v2rayN/Common/Utile.cs | 20 +++++++++---------- .../v2rayN/Converters/MaterialDesignFonts.cs | 2 +- v2rayN/v2rayN/Handler/CoreConfigSingbox.cs | 8 ++++---- v2rayN/v2rayN/Handler/CoreHandler.cs | 4 ++-- v2rayN/v2rayN/Handler/StatisticsSingbox.cs | 2 +- v2rayN/v2rayN/Handler/UpdateHandle.cs | 2 +- v2rayN/v2rayN/ViewModels/SubEditViewModel.cs | 2 +- v2rayN/v2rayN/Views/MsgView.xaml.cs | 2 +- 11 files changed, 30 insertions(+), 30 deletions(-) diff --git a/v2rayN/v2rayN/Common/DownloaderHelper.cs b/v2rayN/v2rayN/Common/DownloaderHelper.cs index 9ae47282..9f4fe963 100644 --- a/v2rayN/v2rayN/Common/DownloaderHelper.cs +++ b/v2rayN/v2rayN/Common/DownloaderHelper.cs @@ -11,7 +11,7 @@ namespace v2rayN public async Task DownloadStringAsync(IWebProxy? webProxy, string url, string? userAgent, int timeout) { - if (string.IsNullOrEmpty(url)) + if (Utile.IsNullOrEmpty(url)) { return null; } @@ -57,7 +57,7 @@ namespace v2rayN public async Task DownloadDataAsync4Speed(IWebProxy webProxy, string url, IProgress progress, int timeout) { - if (string.IsNullOrEmpty(url)) + if (Utile.IsNullOrEmpty(url)) { throw new ArgumentNullException(nameof(url)); } @@ -120,11 +120,11 @@ namespace v2rayN public async Task DownloadFileAsync(IWebProxy? webProxy, string url, string fileName, IProgress progress, int timeout) { - if (string.IsNullOrEmpty(url)) + if (Utile.IsNullOrEmpty(url)) { throw new ArgumentNullException(nameof(url)); } - if (string.IsNullOrEmpty(fileName)) + if (Utile.IsNullOrEmpty(fileName)) { throw new ArgumentNullException(nameof(fileName)); } diff --git a/v2rayN/v2rayN/Common/HttpClientHelper.cs b/v2rayN/v2rayN/Common/HttpClientHelper.cs index 8f541c99..51707be5 100644 --- a/v2rayN/v2rayN/Common/HttpClientHelper.cs +++ b/v2rayN/v2rayN/Common/HttpClientHelper.cs @@ -23,13 +23,13 @@ namespace v2rayN public async Task GetAsync(string url) { - if (string.IsNullOrEmpty(url)) return null; + if (Utile.IsNullOrEmpty(url)) return null; return await httpClient.GetStringAsync(url); } public async Task GetAsync(HttpClient client, string url, CancellationToken token = default) { - if (string.IsNullOrWhiteSpace(url)) return null; + if (Utile.IsNullOrEmpty(url)) return null; return await client.GetStringAsync(url, token); } @@ -88,7 +88,7 @@ namespace v2rayN public async Task DownloadDataAsync4Speed(HttpClient client, string url, IProgress progress, CancellationToken token = default) { - if (string.IsNullOrEmpty(url)) + if (Utile.IsNullOrEmpty(url)) { throw new ArgumentNullException(nameof(url)); } diff --git a/v2rayN/v2rayN/Common/JsonUtile.cs b/v2rayN/v2rayN/Common/JsonUtile.cs index bf585cbd..1c76fc4e 100644 --- a/v2rayN/v2rayN/Common/JsonUtile.cs +++ b/v2rayN/v2rayN/Common/JsonUtile.cs @@ -28,7 +28,7 @@ namespace v2rayN { try { - if (string.IsNullOrEmpty(strJson)) + if (string.IsNullOrWhiteSpace(strJson)) { return default; } @@ -49,7 +49,7 @@ namespace v2rayN { try { - if (string.IsNullOrEmpty(strJson)) + if (string.IsNullOrWhiteSpace(strJson)) { return null; } diff --git a/v2rayN/v2rayN/Common/Utile.cs b/v2rayN/v2rayN/Common/Utile.cs index 13e0b0e3..672b5763 100644 --- a/v2rayN/v2rayN/Common/Utile.cs +++ b/v2rayN/v2rayN/Common/Utile.cs @@ -361,7 +361,7 @@ namespace v2rayN /// public static string GetPunycode(string url) { - if (string.IsNullOrWhiteSpace(url)) + if (Utile.IsNullOrEmpty(url)) { return url; } @@ -391,7 +391,7 @@ namespace v2rayN public static string Convert2Comma(string text) { - if (string.IsNullOrWhiteSpace(text)) + if (Utile.IsNullOrEmpty(text)) { return text; } @@ -428,7 +428,7 @@ namespace v2rayN /// public static bool IsNullOrEmpty(string? text) { - if (string.IsNullOrEmpty(text)) + if (string.IsNullOrWhiteSpace(text)) { return true; } @@ -840,7 +840,7 @@ namespace v2rayN { Directory.CreateDirectory(_tempPath); } - if (string.IsNullOrEmpty(filename)) + if (Utile.IsNullOrEmpty(filename)) { return _tempPath; } @@ -876,7 +876,7 @@ namespace v2rayN { Directory.CreateDirectory(_tempPath); } - if (string.IsNullOrEmpty(filename)) + if (Utile.IsNullOrEmpty(filename)) { return _tempPath; } @@ -901,7 +901,7 @@ namespace v2rayN Directory.CreateDirectory(_tempPath); } } - if (string.IsNullOrEmpty(filename)) + if (Utile.IsNullOrEmpty(filename)) { return _tempPath; } @@ -918,7 +918,7 @@ namespace v2rayN { Directory.CreateDirectory(_tempPath); } - if (string.IsNullOrEmpty(filename)) + if (Utile.IsNullOrEmpty(filename)) { return _tempPath; } @@ -935,7 +935,7 @@ namespace v2rayN { Directory.CreateDirectory(_tempPath); } - if (string.IsNullOrEmpty(filename)) + if (Utile.IsNullOrEmpty(filename)) { return _tempPath; } @@ -1107,7 +1107,7 @@ namespace v2rayN /// public static void AutoStart(string taskName, string fileName, string description) { - if (string.IsNullOrEmpty(taskName)) + if (Utile.IsNullOrEmpty(taskName)) { return; } @@ -1122,7 +1122,7 @@ namespace v2rayN { taskService.RootFolder.DeleteTask(t.Name); } - if (string.IsNullOrEmpty(fileName)) + if (Utile.IsNullOrEmpty(fileName)) { return; } diff --git a/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs b/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs index 313182db..938db7cc 100644 --- a/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs +++ b/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs @@ -12,7 +12,7 @@ namespace v2rayN.Converters try { var fontFamily = LazyConfig.Instance.GetConfig().uiItem.currentFontFamily; - if (!string.IsNullOrEmpty(fontFamily)) + if (!Utile.IsNullOrEmpty(fontFamily)) { var fontPath = Utile.GetFontsPath(); MyFont = new FontFamily(new Uri(@$"file:///{fontPath}\"), $"./#{fontFamily}"); diff --git a/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs b/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs index fd1d8ef3..ab6177ee 100644 --- a/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs +++ b/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs @@ -354,11 +354,11 @@ namespace v2rayN.Handler if (node.streamSecurity == Global.StreamSecurityReality || node.streamSecurity == Global.StreamSecurity) { var server_name = string.Empty; - if (!string.IsNullOrWhiteSpace(node.sni)) + if (!Utile.IsNullOrEmpty(node.sni)) { server_name = node.sni; } - else if (!string.IsNullOrWhiteSpace(node.requestHost)) + else if (!Utile.IsNullOrEmpty(node.requestHost)) { server_name = Utile.String2List(node.requestHost)[0]; } @@ -761,7 +761,7 @@ namespace v2rayN.Handler { var item = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box); var tunDNS = item?.tunDNS; - if (string.IsNullOrWhiteSpace(tunDNS)) + if (Utile.IsNullOrEmpty(tunDNS)) { tunDNS = Utile.GetEmbedText(Global.TunSingboxDNSFileName); } @@ -771,7 +771,7 @@ namespace v2rayN.Handler { var item = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box); var normalDNS = item?.normalDNS; - if (string.IsNullOrWhiteSpace(normalDNS)) + if (Utile.IsNullOrEmpty(normalDNS)) { normalDNS = "{\"servers\":[{\"address\":\"tcp://8.8.8.8\"}]}"; } diff --git a/v2rayN/v2rayN/Handler/CoreHandler.cs b/v2rayN/v2rayN/Handler/CoreHandler.cs index 3f6582dc..2105842b 100644 --- a/v2rayN/v2rayN/Handler/CoreHandler.cs +++ b/v2rayN/v2rayN/Handler/CoreHandler.cs @@ -292,7 +292,7 @@ namespace v2rayN.Handler { proc.OutputDataReceived += (sender, e) => { - if (!string.IsNullOrEmpty(e.Data)) + if (!Utile.IsNullOrEmpty(e.Data)) { string msg = e.Data + Environment.NewLine; ShowMsg(false, msg); @@ -300,7 +300,7 @@ namespace v2rayN.Handler }; proc.ErrorDataReceived += (sender, e) => { - if (!string.IsNullOrEmpty(e.Data)) + if (!Utile.IsNullOrEmpty(e.Data)) { string msg = e.Data + Environment.NewLine; ShowMsg(false, msg); diff --git a/v2rayN/v2rayN/Handler/StatisticsSingbox.cs b/v2rayN/v2rayN/Handler/StatisticsSingbox.cs index 29de41fe..10e29fc0 100644 --- a/v2rayN/v2rayN/Handler/StatisticsSingbox.cs +++ b/v2rayN/v2rayN/Handler/StatisticsSingbox.cs @@ -84,7 +84,7 @@ namespace v2rayN.Handler while (!res.CloseStatus.HasValue) { var result = Encoding.UTF8.GetString(buffer, 0, res.Count); - if (!string.IsNullOrEmpty(result)) + if (!Utile.IsNullOrEmpty(result)) { ParseOutput(result, out ulong up, out ulong down); diff --git a/v2rayN/v2rayN/Handler/UpdateHandle.cs b/v2rayN/v2rayN/Handler/UpdateHandle.cs index 5d7a50df..823e96cf 100644 --- a/v2rayN/v2rayN/Handler/UpdateHandle.cs +++ b/v2rayN/v2rayN/Handler/UpdateHandle.cs @@ -207,7 +207,7 @@ namespace v2rayN.Handler //convert if (!Utile.IsNullOrEmpty(item.convertTarget)) { - var subConvertUrl = string.IsNullOrEmpty(config.constItem.subConvertUrl) ? Global.SubConvertUrls.FirstOrDefault() : config.constItem.subConvertUrl; + var subConvertUrl = Utile.IsNullOrEmpty(config.constItem.subConvertUrl) ? Global.SubConvertUrls.FirstOrDefault() : config.constItem.subConvertUrl; url = string.Format(subConvertUrl!, Utile.UrlEncode(url)); if (!url.Contains("target=")) { diff --git a/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs b/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs index ce20356f..41da092b 100644 --- a/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs @@ -46,7 +46,7 @@ namespace v2rayN.ViewModels private void SaveSub() { string remarks = SelectedSource.remarks; - if (string.IsNullOrEmpty(remarks)) + if (Utile.IsNullOrEmpty(remarks)) { _noticeHandler?.Enqueue(ResUI.PleaseFillRemarks); return; diff --git a/v2rayN/v2rayN/Views/MsgView.xaml.cs b/v2rayN/v2rayN/Views/MsgView.xaml.cs index 6d207f92..66c83091 100644 --- a/v2rayN/v2rayN/Views/MsgView.xaml.cs +++ b/v2rayN/v2rayN/Views/MsgView.xaml.cs @@ -48,7 +48,7 @@ namespace v2rayN.Views var MsgFilter = cmbMsgFilter.Text.TrimEx(); if (MsgFilter != lastMsgFilter) lastMsgFilterNotAvailable = false; - if (!string.IsNullOrEmpty(MsgFilter) && !lastMsgFilterNotAvailable) + if (!Utile.IsNullOrEmpty(MsgFilter) && !lastMsgFilterNotAvailable) { try {