From 71cc6d7a882e3d0ad0cfa6ed8c04a5f340341403 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 5 Mar 2025 19:44:49 +0800 Subject: [PATCH] Replace all Utils.IsNullOrEmpty(variable) with variable.IsNullOrEmpty() --- v2rayN/ServiceLib/Common/DownloaderHelper.cs | 8 ++-- v2rayN/ServiceLib/Common/HttpClientHelper.cs | 8 ++-- v2rayN/ServiceLib/Common/Utils.cs | 31 +++++------- v2rayN/ServiceLib/Common/WindowsUtils.cs | 4 +- v2rayN/ServiceLib/Handler/AppHandler.cs | 6 +-- .../ServiceLib/Handler/AutoStartupHandler.cs | 4 +- v2rayN/ServiceLib/Handler/ConfigHandler.cs | 48 +++++++++---------- v2rayN/ServiceLib/Handler/CoreHandler.cs | 6 +-- v2rayN/ServiceLib/Handler/Fmt/FmtHandler.cs | 2 +- .../Handler/SysProxy/SysProxyHandler.cs | 2 +- v2rayN/ServiceLib/Models/ProfileItem.cs | 4 +- .../CoreConfig/CoreConfigClashService.cs | 2 +- .../CoreConfig/CoreConfigSingboxService.cs | 44 ++++++++--------- .../CoreConfig/CoreConfigV2rayService.cs | 26 +++++----- v2rayN/ServiceLib/Services/DownloadService.cs | 4 +- v2rayN/ServiceLib/Services/UpdateService.cs | 16 +++---- .../ViewModels/AddServer2ViewModel.cs | 8 ++-- .../ViewModels/AddServerViewModel.cs | 12 ++--- .../ViewModels/BackupAndRestoreViewModel.cs | 4 +- .../ViewModels/ClashConnectionsViewModel.cs | 2 +- .../ViewModels/ClashProxiesViewModel.cs | 14 +++--- .../ViewModels/MainWindowViewModel.cs | 4 +- .../ViewModels/OptionSettingViewModel.cs | 2 +- .../ViewModels/ProfilesViewModel.cs | 20 ++++---- .../ViewModels/RoutingRuleSettingViewModel.cs | 10 ++-- .../ViewModels/StatusBarViewModel.cs | 2 +- .../ServiceLib/ViewModels/SubEditViewModel.cs | 2 +- .../Views/AddServerWindow.axaml.cs | 4 +- .../Views/ProfilesView.axaml.cs | 2 +- .../Views/SubSettingWindow.axaml.cs | 2 +- v2rayN/v2rayN/Handler/WindowsHandler.cs | 2 +- v2rayN/v2rayN/Views/AddServerWindow.xaml.cs | 4 +- .../v2rayN/Views/OptionSettingWindow.xaml.cs | 4 +- v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs | 2 +- 34 files changed, 153 insertions(+), 162 deletions(-) diff --git a/v2rayN/ServiceLib/Common/DownloaderHelper.cs b/v2rayN/ServiceLib/Common/DownloaderHelper.cs index 1da4870c..570a95f5 100644 --- a/v2rayN/ServiceLib/Common/DownloaderHelper.cs +++ b/v2rayN/ServiceLib/Common/DownloaderHelper.cs @@ -10,7 +10,7 @@ namespace ServiceLib.Common public async Task DownloadStringAsync(IWebProxy? webProxy, string url, string? userAgent, int timeout) { - if (Utils.IsNullOrEmpty(url)) + if (url.IsNullOrEmpty()) { return null; } @@ -56,7 +56,7 @@ namespace ServiceLib.Common public async Task DownloadDataAsync4Speed(IWebProxy webProxy, string url, IProgress progress, int timeout) { - if (Utils.IsNullOrEmpty(url)) + if (url.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(url)); } @@ -119,11 +119,11 @@ namespace ServiceLib.Common public async Task DownloadFileAsync(IWebProxy? webProxy, string url, string fileName, IProgress progress, int timeout) { - if (Utils.IsNullOrEmpty(url)) + if (url.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(url)); } - if (Utils.IsNullOrEmpty(fileName)) + if (fileName.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(fileName)); } diff --git a/v2rayN/ServiceLib/Common/HttpClientHelper.cs b/v2rayN/ServiceLib/Common/HttpClientHelper.cs index 9c8082a0..d2d4924f 100644 --- a/v2rayN/ServiceLib/Common/HttpClientHelper.cs +++ b/v2rayN/ServiceLib/Common/HttpClientHelper.cs @@ -22,7 +22,7 @@ namespace ServiceLib.Common public async Task TryGetAsync(string url) { - if (Utils.IsNullOrEmpty(url)) + if (url.IsNullOrEmpty()) return null; try @@ -38,14 +38,14 @@ namespace ServiceLib.Common public async Task GetAsync(string url) { - if (Utils.IsNullOrEmpty(url)) + if (url.IsNullOrEmpty()) return null; return await httpClient.GetStringAsync(url); } public async Task GetAsync(HttpClient client, string url, CancellationToken token = default) { - if (Utils.IsNullOrEmpty(url)) + if (url.IsNullOrEmpty()) return null; return await client.GetStringAsync(url, token); } @@ -123,7 +123,7 @@ namespace ServiceLib.Common public async Task DownloadDataAsync4Speed(HttpClient client, string url, IProgress progress, CancellationToken token = default) { - if (Utils.IsNullOrEmpty(url)) + if (url.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(url)); } diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index 38221a2b..48210b3f 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -252,7 +252,7 @@ namespace ServiceLib.Common public static NameValueCollection ParseQueryString(string query) { var result = new NameValueCollection(StringComparer.OrdinalIgnoreCase); - if (IsNullOrEmpty(query)) + if (query.IsNullOrEmpty()) { return result; } @@ -298,7 +298,7 @@ namespace ServiceLib.Common /// public static string GetPunycode(string url) { - if (Utils.IsNullOrEmpty(url)) + if (url.IsNullOrEmpty()) { return url; } @@ -331,7 +331,7 @@ namespace ServiceLib.Common public static string Convert2Comma(string text) { - if (IsNullOrEmpty(text)) + if (text.IsNullOrEmpty()) { return text; } @@ -353,15 +353,6 @@ namespace ServiceLib.Common return oText.All(char.IsNumber); } - public static bool IsNullOrEmpty(string? text) - { - if (string.IsNullOrWhiteSpace(text)) - { - return true; - } - - return text == "null"; - } /// /// 验证Domain地址是否合法 @@ -369,7 +360,7 @@ namespace ServiceLib.Common /// public static bool IsDomain(string? domain) { - if (IsNullOrEmpty(domain)) + if (domain.IsNullOrEmpty()) { return false; } @@ -655,7 +646,7 @@ namespace ServiceLib.Common public static string GetPath(string fileName) { var startupPath = StartupPath(); - if (IsNullOrEmpty(fileName)) + if (fileName.IsNullOrEmpty()) { return startupPath; } @@ -691,7 +682,7 @@ namespace ServiceLib.Common Directory.CreateDirectory(tempPath); } - if (IsNullOrEmpty(filename)) + if (filename.IsNullOrEmpty()) { return tempPath; } @@ -720,7 +711,7 @@ namespace ServiceLib.Common Directory.CreateDirectory(tempPath); } - if (Utils.IsNullOrEmpty(filename)) + if (filename.IsNullOrEmpty()) { return tempPath; } @@ -747,7 +738,7 @@ namespace ServiceLib.Common } } - if (IsNullOrEmpty(filename)) + if (filename.IsNullOrEmpty()) { return tempPath; } @@ -765,7 +756,7 @@ namespace ServiceLib.Common Directory.CreateDirectory(tempPath); } - if (Utils.IsNullOrEmpty(filename)) + if (filename.IsNullOrEmpty()) { return tempPath; } @@ -783,7 +774,7 @@ namespace ServiceLib.Common Directory.CreateDirectory(tempPath); } - if (Utils.IsNullOrEmpty(filename)) + if (filename.IsNullOrEmpty()) { return tempPath; } @@ -801,7 +792,7 @@ namespace ServiceLib.Common Directory.CreateDirectory(tempPath); } - if (Utils.IsNullOrEmpty(filename)) + if (filename.IsNullOrEmpty()) { return tempPath; } diff --git a/v2rayN/ServiceLib/Common/WindowsUtils.cs b/v2rayN/ServiceLib/Common/WindowsUtils.cs index 77877d60..bead7899 100644 --- a/v2rayN/ServiceLib/Common/WindowsUtils.cs +++ b/v2rayN/ServiceLib/Common/WindowsUtils.cs @@ -15,7 +15,7 @@ namespace ServiceLib.Common { regKey = Registry.CurrentUser.OpenSubKey(path, false); var value = regKey?.GetValue(name) as string; - return Utils.IsNullOrEmpty(value) ? def : value; + return value.IsNullOrEmpty() ? def : value; } catch (Exception ex) { @@ -34,7 +34,7 @@ namespace ServiceLib.Common try { regKey = Registry.CurrentUser.CreateSubKey(path); - if (Utils.IsNullOrEmpty(value.ToString())) + if (value.ToString().IsNullOrEmpty()) { regKey?.DeleteValue(name, false); } diff --git a/v2rayN/ServiceLib/Handler/AppHandler.cs b/v2rayN/ServiceLib/Handler/AppHandler.cs index 5c514696..0ac794ac 100644 --- a/v2rayN/ServiceLib/Handler/AppHandler.cs +++ b/v2rayN/ServiceLib/Handler/AppHandler.cs @@ -131,7 +131,7 @@ namespace ServiceLib.Handler public async Task?> ProfileItems(string subid) { - if (Utils.IsNullOrEmpty(subid)) + if (subid.IsNullOrEmpty()) { return await SQLiteHelper.Instance.TableAsync().ToListAsync(); } @@ -171,7 +171,7 @@ namespace ServiceLib.Handler public async Task GetProfileItem(string indexId) { - if (Utils.IsNullOrEmpty(indexId)) + if (indexId.IsNullOrEmpty()) { return null; } @@ -180,7 +180,7 @@ namespace ServiceLib.Handler public async Task GetProfileItemViaRemarks(string? remarks) { - if (Utils.IsNullOrEmpty(remarks)) + if (remarks.IsNullOrEmpty()) { return null; } diff --git a/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs b/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs index cb742d4c..4ba63ba8 100644 --- a/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs +++ b/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs @@ -85,7 +85,7 @@ namespace ServiceLib.Handler /// public static void AutoStartTaskService(string taskName, string fileName, string description) { - if (Utils.IsNullOrEmpty(taskName)) + if (taskName.IsNullOrEmpty()) { return; } @@ -93,7 +93,7 @@ namespace ServiceLib.Handler var logonUser = WindowsIdentity.GetCurrent().Name; using var taskService = new Microsoft.Win32.TaskScheduler.TaskService(); var tasks = taskService.RootFolder.GetTasks(new Regex(taskName)); - if (Utils.IsNullOrEmpty(fileName)) + if (fileName.IsNullOrEmpty()) { foreach (var t in tasks) { diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index c506db10..5f2c0166 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -67,7 +67,7 @@ namespace ServiceLib.Handler } config.RoutingBasicItem ??= new(); - if (Utils.IsNullOrEmpty(config.RoutingBasicItem.DomainStrategy)) + if (config.RoutingBasicItem.DomainStrategy.IsNullOrEmpty()) { config.RoutingBasicItem.DomainStrategy = Global.DomainStrategies.First(); } @@ -103,7 +103,7 @@ namespace ServiceLib.Handler }; config.UiItem.MainColumnItem ??= new(); - if (Utils.IsNullOrEmpty(config.UiItem.CurrentLanguage)) + if (config.UiItem.CurrentLanguage.IsNullOrEmpty()) { config.UiItem.CurrentLanguage = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName.Equals("zh", StringComparison.CurrentCultureIgnoreCase) ? Global.Languages.First() @@ -117,11 +117,11 @@ namespace ServiceLib.Handler { config.SpeedTestItem.SpeedTestTimeout = 10; } - if (Utils.IsNullOrEmpty(config.SpeedTestItem.SpeedTestUrl)) + if (config.SpeedTestItem.SpeedTestUrl.IsNullOrEmpty()) { config.SpeedTestItem.SpeedTestUrl = Global.SpeedTestUrls.First(); } - if (Utils.IsNullOrEmpty(config.SpeedTestItem.SpeedPingTestUrl)) + if (config.SpeedTestItem.SpeedPingTestUrl.IsNullOrEmpty()) { config.SpeedTestItem.SpeedPingTestUrl = Global.SpeedPingTestUrl; } @@ -354,7 +354,7 @@ namespace ServiceLib.Handler /// public static async Task SetDefaultServerIndex(Config config, string? indexId) { - if (Utils.IsNullOrEmpty(indexId)) + if (indexId.IsNullOrEmpty()) { return -1; } @@ -506,7 +506,7 @@ namespace ServiceLib.Handler profileItem.Address = newFileName; profileItem.ConfigType = EConfigType.Custom; - if (Utils.IsNullOrEmpty(profileItem.Remarks)) + if (profileItem.Remarks.IsNullOrEmpty()) { profileItem.Remarks = $"import custom@{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")}"; } @@ -624,7 +624,7 @@ namespace ServiceLib.Handler profileItem.Address = profileItem.Address.TrimEx(); profileItem.Id = profileItem.Id.TrimEx(); - if (Utils.IsNullOrEmpty(profileItem.StreamSecurity)) + if (profileItem.StreamSecurity.IsNullOrEmpty()) { profileItem.StreamSecurity = Global.StreamSecurity; } @@ -654,7 +654,7 @@ namespace ServiceLib.Handler profileItem.Path = profileItem.Path.TrimEx(); profileItem.Network = string.Empty; - if (Utils.IsNullOrEmpty(profileItem.StreamSecurity)) + if (profileItem.StreamSecurity.IsNullOrEmpty()) { profileItem.StreamSecurity = Global.StreamSecurity; } @@ -689,11 +689,11 @@ namespace ServiceLib.Handler profileItem.HeaderType = Global.TuicCongestionControls.FirstOrDefault()!; } - if (Utils.IsNullOrEmpty(profileItem.StreamSecurity)) + if (profileItem.StreamSecurity.IsNullOrEmpty()) { profileItem.StreamSecurity = Global.StreamSecurity; } - if (Utils.IsNullOrEmpty(profileItem.Alpn)) + if (profileItem.Alpn.IsNullOrEmpty()) { profileItem.Alpn = "h3"; } @@ -906,11 +906,11 @@ namespace ServiceLib.Handler } else { - if (Utils.IsNullOrEmpty(profileItem.AllowInsecure)) + if (profileItem.AllowInsecure.IsNullOrEmpty()) { profileItem.AllowInsecure = config.CoreBasicItem.DefAllowInsecure.ToString().ToLower(); } - if (Utils.IsNullOrEmpty(profileItem.Fingerprint) && profileItem.StreamSecurity == Global.StreamSecurityReality) + if (profileItem.Fingerprint.IsNullOrEmpty() && profileItem.StreamSecurity == Global.StreamSecurityReality) { profileItem.Fingerprint = config.CoreBasicItem.DefFingerprint; } @@ -923,7 +923,7 @@ namespace ServiceLib.Handler } var maxSort = -1; - if (Utils.IsNullOrEmpty(profileItem.IndexId)) + if (profileItem.IndexId.IsNullOrEmpty()) { profileItem.IndexId = Utils.GetGuid(false); maxSort = ProfileExHandler.Instance.GetMaxSort(); @@ -1084,7 +1084,7 @@ namespace ServiceLib.Handler /// 成功导入的数量 private static async Task AddBatchServersCommon(Config config, string strData, string subid, bool isSub) { - if (Utils.IsNullOrEmpty(strData)) + if (strData.IsNullOrEmpty()) { return -1; } @@ -1163,7 +1163,7 @@ namespace ServiceLib.Handler private static async Task AddBatchServers4Custom(Config config, string strData, string subid, bool isSub) { - if (Utils.IsNullOrEmpty(strData)) + if (strData.IsNullOrEmpty()) { return -1; } @@ -1236,7 +1236,7 @@ namespace ServiceLib.Handler { profileItem = NaiveproxyFmt.ResolveFull(strData, subRemarks); } - if (profileItem is null || Utils.IsNullOrEmpty(profileItem.Address)) + if (profileItem is null || profileItem.Address.IsNullOrEmpty()) { return -1; } @@ -1261,7 +1261,7 @@ namespace ServiceLib.Handler private static async Task AddBatchServers4SsSIP008(Config config, string strData, string subid, bool isSub) { - if (Utils.IsNullOrEmpty(strData)) + if (strData.IsNullOrEmpty()) { return -1; } @@ -1293,7 +1293,7 @@ namespace ServiceLib.Handler public static async Task AddBatchServers(Config config, string strData, string subid, bool isSub) { - if (Utils.IsNullOrEmpty(strData)) + if (strData.IsNullOrEmpty()) { return -1; } @@ -1424,7 +1424,7 @@ namespace ServiceLib.Handler item.Memo = subItem.Memo; } - if (Utils.IsNullOrEmpty(item.Id)) + if (item.Id.IsNullOrEmpty()) { item.Id = Utils.GetGuid(false); @@ -1457,7 +1457,7 @@ namespace ServiceLib.Handler /// public static async Task RemoveServersViaSubid(Config config, string subid, bool isSub) { - if (Utils.IsNullOrEmpty(subid)) + if (subid.IsNullOrEmpty()) { return -1; } @@ -1508,7 +1508,7 @@ namespace ServiceLib.Handler public static async Task SaveRoutingItem(Config config, RoutingItem item) { - if (Utils.IsNullOrEmpty(item.Id)) + if (item.Id.IsNullOrEmpty()) { item.Id = Utils.GetGuid(false); } @@ -1531,7 +1531,7 @@ namespace ServiceLib.Handler /// public static async Task AddBatchRoutingRules(RoutingItem routingItem, string strData) { - if (Utils.IsNullOrEmpty(strData)) + if (strData.IsNullOrEmpty()) { return -1; } @@ -1549,7 +1549,7 @@ namespace ServiceLib.Handler routingItem.RuleNum = lstRules.Count; routingItem.RuleSet = JsonUtils.Serialize(lstRules, false); - if (Utils.IsNullOrEmpty(routingItem.Id)) + if (routingItem.Id.IsNullOrEmpty()) { routingItem.Id = Utils.GetGuid(false); } @@ -1820,7 +1820,7 @@ namespace ServiceLib.Handler return -1; } - if (Utils.IsNullOrEmpty(item.Id)) + if (item.Id.IsNullOrEmpty()) { item.Id = Utils.GetGuid(false); } diff --git a/v2rayN/ServiceLib/Handler/CoreHandler.cs b/v2rayN/ServiceLib/Handler/CoreHandler.cs index 8f6200b9..0c05db64 100644 --- a/v2rayN/ServiceLib/Handler/CoreHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreHandler.cs @@ -240,7 +240,7 @@ namespace ServiceLib.Handler private async Task RunProcess(CoreInfo? coreInfo, string configPath, bool displayLog, bool mayNeedSudo) { var fileName = CoreInfoHandler.Instance.GetCoreExecFile(coreInfo, out var msg); - if (Utils.IsNullOrEmpty(fileName)) + if (fileName.IsNullOrEmpty()) { UpdateFunc(false, msg); return null; @@ -274,13 +274,13 @@ namespace ServiceLib.Handler { proc.OutputDataReceived += (sender, e) => { - if (Utils.IsNullOrEmpty(e.Data)) + if (e.Data.IsNullOrEmpty()) return; UpdateFunc(false, e.Data + Environment.NewLine); }; proc.ErrorDataReceived += (sender, e) => { - if (Utils.IsNullOrEmpty(e.Data)) + if (e.Data.IsNullOrEmpty()) return; UpdateFunc(false, e.Data + Environment.NewLine); }; diff --git a/v2rayN/ServiceLib/Handler/Fmt/FmtHandler.cs b/v2rayN/ServiceLib/Handler/Fmt/FmtHandler.cs index 1830c8af..b2d5ac58 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/FmtHandler.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/FmtHandler.cs @@ -37,7 +37,7 @@ try { string str = config.TrimEx(); - if (Utils.IsNullOrEmpty(str)) + if (str.IsNullOrEmpty()) { msg = ResUI.FailedReadConfiguration; return null; diff --git a/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs b/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs index 99cc991a..6d8a9b44 100644 --- a/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs +++ b/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs @@ -75,7 +75,7 @@ } strProxy = string.Empty; - if (Utils.IsNullOrEmpty(config.SystemProxyItem.SystemProxyAdvancedProtocol)) + if (config.SystemProxyItem.SystemProxyAdvancedProtocol.IsNullOrEmpty()) { strProxy = $"{Global.Loopback}:{port}"; } diff --git a/v2rayN/ServiceLib/Models/ProfileItem.cs b/v2rayN/ServiceLib/Models/ProfileItem.cs index 5f708103..db752a75 100644 --- a/v2rayN/ServiceLib/Models/ProfileItem.cs +++ b/v2rayN/ServiceLib/Models/ProfileItem.cs @@ -48,12 +48,12 @@ namespace ServiceLib.Models public List? GetAlpn() { - return Utils.IsNullOrEmpty(Alpn) ? null : Utils.String2List(Alpn); + return Alpn.IsNullOrEmpty() ? null : Utils.String2List(Alpn); } public string GetNetwork() { - if (Utils.IsNullOrEmpty(Network) || !Global.Networks.Contains(Network)) + if (Network.IsNullOrEmpty() || !Global.Networks.Contains(Network)) { return Global.DefaultNetwork; } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs index 4d3b5e87..da17183c 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs @@ -45,7 +45,7 @@ namespace ServiceLib.Services.CoreConfig } string addressFileName = node.Address; - if (Utils.IsNullOrEmpty(addressFileName)) + if (addressFileName.IsNullOrEmpty()) { ret.Msg = ResUI.FailedGetDefaultConfiguration; return ret; diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs index 183fce0c..6fe4d4d5 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs @@ -36,7 +36,7 @@ namespace ServiceLib.Services.CoreConfig ret.Msg = ResUI.InitialConfiguration; string result = EmbedUtils.GetEmbedText(Global.SingboxSampleClient); - if (Utils.IsNullOrEmpty(result)) + if (result.IsNullOrEmpty()) { ret.Msg = ResUI.FailedGetDefaultConfiguration; return ret; @@ -93,7 +93,7 @@ namespace ServiceLib.Services.CoreConfig var result = EmbedUtils.GetEmbedText(Global.SingboxSampleClient); var txtOutbound = EmbedUtils.GetEmbedText(Global.SingboxSampleOutbound); - if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty()) + if (result.IsNullOrEmpty() || txtOutbound.IsNullOrEmpty()) { ret.Msg = ResUI.FailedGetDefaultConfiguration; return ret; @@ -138,7 +138,7 @@ namespace ServiceLib.Services.CoreConfig var item = await AppHandler.Instance.GetProfileItem(it.IndexId); if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS) { - if (item is null || Utils.IsNullOrEmpty(item.Id) || !Utils.IsGuidByParse(item.Id)) + if (item is null || item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id)) { continue; } @@ -261,7 +261,7 @@ namespace ServiceLib.Services.CoreConfig ret.Msg = ResUI.InitialConfiguration; var result = EmbedUtils.GetEmbedText(Global.SingboxSampleClient); - if (Utils.IsNullOrEmpty(result)) + if (result.IsNullOrEmpty()) { ret.Msg = ResUI.FailedGetDefaultConfiguration; return ret; @@ -317,7 +317,7 @@ namespace ServiceLib.Services.CoreConfig string result = EmbedUtils.GetEmbedText(Global.SingboxSampleClient); string txtOutbound = EmbedUtils.GetEmbedText(Global.SingboxSampleOutbound); - if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty()) + if (result.IsNullOrEmpty() || txtOutbound.IsNullOrEmpty()) { ret.Msg = ResUI.FailedGetDefaultConfiguration; return ret; @@ -354,7 +354,7 @@ namespace ServiceLib.Services.CoreConfig } if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS) { - if (Utils.IsNullOrEmpty(item.Id) || !Utils.IsGuidByParse(item.Id)) + if (item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id)) { continue; } @@ -443,7 +443,7 @@ namespace ServiceLib.Services.CoreConfig } string addressFileName = node.Address; - if (Utils.IsNullOrEmpty(addressFileName)) + if (addressFileName.IsNullOrEmpty()) { ret.Msg = ResUI.FailedGetDefaultConfiguration; return ret; @@ -560,7 +560,7 @@ namespace ServiceLib.Services.CoreConfig inbound.listen_port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks); inbound.sniff = _config.Inbound.First().SniffingEnabled; inbound.sniff_override_destination = _config.Inbound.First().RouteOnly ? false : _config.Inbound.First().SniffingEnabled; - inbound.domain_strategy = Utils.IsNullOrEmpty(_config.RoutingBasicItem.DomainStrategy4Singbox) ? null : _config.RoutingBasicItem.DomainStrategy4Singbox; + inbound.domain_strategy = _config.RoutingBasicItem.DomainStrategy4Singbox.IsNullOrEmpty() ? null : _config.RoutingBasicItem.DomainStrategy4Singbox; var routing = await ConfigHandler.GetDefaultRouting(_config); if (routing.DomainStrategy4Singbox.IsNotEmpty()) @@ -601,7 +601,7 @@ namespace ServiceLib.Services.CoreConfig { _config.TunModeItem.Mtu = Global.TunMtus.First(); } - if (Utils.IsNullOrEmpty(_config.TunModeItem.Stack)) + if (_config.TunModeItem.Stack.IsNullOrEmpty()) { _config.TunModeItem.Stack = Global.TunStacks.First(); } @@ -698,7 +698,7 @@ namespace ServiceLib.Services.CoreConfig outbound.packet_encoding = "xudp"; - if (Utils.IsNullOrEmpty(node.Flow)) + if (node.Flow.IsNullOrEmpty()) { await GenOutboundMux(node, outbound); } @@ -854,8 +854,8 @@ namespace ServiceLib.Services.CoreConfig { case nameof(ETransport.h2): transport.type = nameof(ETransport.http); - transport.host = Utils.IsNullOrEmpty(node.RequestHost) ? null : Utils.String2List(node.RequestHost); - transport.path = Utils.IsNullOrEmpty(node.Path) ? null : node.Path; + transport.host = node.RequestHost.IsNullOrEmpty() ? null : Utils.String2List(node.RequestHost); + transport.path = node.Path.IsNullOrEmpty() ? null : node.Path; break; case nameof(ETransport.tcp): //http @@ -869,15 +869,15 @@ namespace ServiceLib.Services.CoreConfig else { transport.type = nameof(ETransport.http); - transport.host = Utils.IsNullOrEmpty(node.RequestHost) ? null : Utils.String2List(node.RequestHost); - transport.path = Utils.IsNullOrEmpty(node.Path) ? null : node.Path; + transport.host = node.RequestHost.IsNullOrEmpty() ? null : Utils.String2List(node.RequestHost); + transport.path = node.Path.IsNullOrEmpty() ? null : node.Path; } } break; case nameof(ETransport.ws): transport.type = nameof(ETransport.ws); - transport.path = Utils.IsNullOrEmpty(node.Path) ? null : node.Path; + transport.path = node.Path.IsNullOrEmpty() ? null : node.Path; if (node.RequestHost.IsNotEmpty()) { transport.headers = new() @@ -889,8 +889,8 @@ namespace ServiceLib.Services.CoreConfig case nameof(ETransport.httpupgrade): transport.type = nameof(ETransport.httpupgrade); - transport.path = Utils.IsNullOrEmpty(node.Path) ? null : node.Path; - transport.host = Utils.IsNullOrEmpty(node.RequestHost) ? null : node.RequestHost; + transport.path = node.Path.IsNullOrEmpty() ? null : node.Path; + transport.host = node.RequestHost.IsNullOrEmpty() ? null : node.RequestHost; break; @@ -1241,11 +1241,11 @@ namespace ServiceLib.Services.CoreConfig var strDNS = string.Empty; if (_config.TunModeItem.EnableTun) { - strDNS = Utils.IsNullOrEmpty(item?.TunDNS) ? EmbedUtils.GetEmbedText(Global.TunSingboxDNSFileName) : item?.TunDNS; + strDNS = string.IsNullOrEmpty(item?.TunDNS) ? EmbedUtils.GetEmbedText(Global.TunSingboxDNSFileName) : item?.TunDNS; } else { - strDNS = Utils.IsNullOrEmpty(item?.NormalDNS) ? EmbedUtils.GetEmbedText(Global.DNSSingboxNormalFileName) : item?.NormalDNS; + strDNS = string.IsNullOrEmpty(item?.NormalDNS) ? EmbedUtils.GetEmbedText(Global.DNSSingboxNormalFileName) : item?.NormalDNS; } var dns4Sbox = JsonUtils.Deserialize(strDNS); @@ -1274,9 +1274,9 @@ namespace ServiceLib.Services.CoreConfig dns4Sbox.servers.Add(new() { tag = tag, - address = Utils.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.SingboxDomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress, + address = string.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.SingboxDomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress, detour = Global.DirectTag, - strategy = Utils.IsNullOrEmpty(dNSItem?.DomainStrategy4Freedom) ? null : dNSItem?.DomainStrategy4Freedom, + strategy = string.IsNullOrEmpty(dNSItem?.DomainStrategy4Freedom) ? null : dNSItem?.DomainStrategy4Freedom, }); dns4Sbox.rules.Insert(0, new() { @@ -1414,7 +1414,7 @@ namespace ServiceLib.Services.CoreConfig singboxConfig.route.rule_set = []; foreach (var item in new HashSet(ruleSets)) { - if (Utils.IsNullOrEmpty(item)) + if (item.IsNullOrEmpty()) { continue; } var customRuleset = customRulesets.FirstOrDefault(t => t.tag != null && t.tag.Equals(item)); if (customRuleset is null) diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs index 30d45644..5c23ca19 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs @@ -37,7 +37,7 @@ namespace ServiceLib.Services.CoreConfig ret.Msg = ResUI.InitialConfiguration; var result = EmbedUtils.GetEmbedText(Global.V2raySampleClient); - if (Utils.IsNullOrEmpty(result)) + if (result.IsNullOrEmpty()) { ret.Msg = ResUI.FailedGetDefaultConfiguration; return ret; @@ -93,7 +93,7 @@ namespace ServiceLib.Services.CoreConfig string result = EmbedUtils.GetEmbedText(Global.V2raySampleClient); string txtOutbound = EmbedUtils.GetEmbedText(Global.V2raySampleOutbound); - if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty()) + if (result.IsNullOrEmpty() || txtOutbound.IsNullOrEmpty()) { ret.Msg = ResUI.FailedGetDefaultConfiguration; return ret; @@ -135,7 +135,7 @@ namespace ServiceLib.Services.CoreConfig } if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS) { - if (Utils.IsNullOrEmpty(item.Id) || !Utils.IsGuidByParse(item.Id)) + if (item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id)) { continue; } @@ -216,7 +216,7 @@ namespace ServiceLib.Services.CoreConfig var result = EmbedUtils.GetEmbedText(Global.V2raySampleClient); var txtOutbound = EmbedUtils.GetEmbedText(Global.V2raySampleOutbound); - if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty()) + if (result.IsNullOrEmpty() || txtOutbound.IsNullOrEmpty()) { ret.Msg = ResUI.FailedGetDefaultConfiguration; return ret; @@ -261,7 +261,7 @@ namespace ServiceLib.Services.CoreConfig var item = await AppHandler.Instance.GetProfileItem(it.IndexId); if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS) { - if (item is null || Utils.IsNullOrEmpty(item.Id) || !Utils.IsGuidByParse(item.Id)) + if (item is null || item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id)) { continue; } @@ -371,7 +371,7 @@ namespace ServiceLib.Services.CoreConfig } var result = EmbedUtils.GetEmbedText(Global.V2raySampleClient); - if (Utils.IsNullOrEmpty(result)) + if (result.IsNullOrEmpty()) { ret.Msg = ResUI.FailedGetDefaultConfiguration; return ret; @@ -487,7 +487,7 @@ namespace ServiceLib.Services.CoreConfig private Inbounds4Ray GetInbound(InItem inItem, EInboundProtocol protocol, bool bSocks) { string result = EmbedUtils.GetEmbedText(Global.V2raySampleInbound); - if (Utils.IsNullOrEmpty(result)) + if (result.IsNullOrEmpty()) { return new(); } @@ -515,7 +515,7 @@ namespace ServiceLib.Services.CoreConfig if (v2rayConfig.routing?.rules != null) { v2rayConfig.routing.domainStrategy = _config.RoutingBasicItem.DomainStrategy; - v2rayConfig.routing.domainMatcher = Utils.IsNullOrEmpty(_config.RoutingBasicItem.DomainMatcher) ? null : _config.RoutingBasicItem.DomainMatcher; + v2rayConfig.routing.domainMatcher = _config.RoutingBasicItem.DomainMatcher.IsNullOrEmpty() ? null : _config.RoutingBasicItem.DomainMatcher; var routing = await ConfigHandler.GetDefaultRouting(_config); if (routing != null) @@ -551,11 +551,11 @@ namespace ServiceLib.Services.CoreConfig { return 0; } - if (Utils.IsNullOrEmpty(rule.port)) + if (rule.port.IsNullOrEmpty()) { rule.port = null; } - if (Utils.IsNullOrEmpty(rule.network)) + if (rule.network.IsNullOrEmpty()) { rule.network = null; } @@ -1027,7 +1027,7 @@ namespace ServiceLib.Services.CoreConfig case nameof(ETransport.grpc): GrpcSettings4Ray grpcSettings = new() { - authority = Utils.IsNullOrEmpty(host) ? null : host, + authority = host.IsNullOrEmpty() ? null : host, serviceName = path, multiMode = node.HeaderType == Global.GrpcMultiMode, idle_timeout = _config.GrpcItem.IdleTimeout, @@ -1085,7 +1085,7 @@ namespace ServiceLib.Services.CoreConfig var item = await AppHandler.Instance.GetDNSItem(ECoreType.Xray); var normalDNS = item?.NormalDNS; var domainStrategy4Freedom = item?.DomainStrategy4Freedom; - if (Utils.IsNullOrEmpty(normalDNS)) + if (normalDNS.IsNullOrEmpty()) { normalDNS = EmbedUtils.GetEmbedText(Global.DNSV2rayNormalFileName); } @@ -1156,7 +1156,7 @@ namespace ServiceLib.Services.CoreConfig { var dnsServer = new DnsServer4Ray() { - address = Utils.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.DomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress, + address = string.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.DomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress, domains = [node.Address] }; servers.AsArray().Add(JsonUtils.SerializeToNode(dnsServer)); diff --git a/v2rayN/ServiceLib/Services/DownloadService.cs b/v2rayN/ServiceLib/Services/DownloadService.cs index 86af7553..f7582d83 100644 --- a/v2rayN/ServiceLib/Services/DownloadService.cs +++ b/v2rayN/ServiceLib/Services/DownloadService.cs @@ -160,7 +160,7 @@ namespace ServiceLib.Services UseProxy = webProxy != null }); - if (Utils.IsNullOrEmpty(userAgent)) + if (userAgent.IsNullOrEmpty()) { userAgent = Utils.GetVersion(false); } @@ -201,7 +201,7 @@ namespace ServiceLib.Services var webProxy = await GetWebProxy(blProxy); - if (Utils.IsNullOrEmpty(userAgent)) + if (userAgent.IsNullOrEmpty()) { userAgent = Utils.GetVersion(false); } diff --git a/v2rayN/ServiceLib/Services/UpdateService.cs b/v2rayN/ServiceLib/Services/UpdateService.cs index 9700f249..0452f087 100644 --- a/v2rayN/ServiceLib/Services/UpdateService.cs +++ b/v2rayN/ServiceLib/Services/UpdateService.cs @@ -123,7 +123,7 @@ namespace ServiceLib.Services var url = item.Url.TrimEx(); var userAgent = item.UserAgent.TrimEx(); var hashCode = $"{item.Remarks}->"; - if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url) || (subId.IsNotEmpty() && item.Id != subId)) + if (id.IsNullOrEmpty() || url.IsNullOrEmpty() || (subId.IsNotEmpty() && item.Id != subId)) { //_updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgNoValidSubscription}"); continue; @@ -151,7 +151,7 @@ namespace ServiceLib.Services //convert if (item.ConvertTarget.IsNotEmpty()) { - var subConvertUrl = Utils.IsNullOrEmpty(config.ConstItem.SubConvertUrl) ? Global.SubConvertUrls.FirstOrDefault() : config.ConstItem.SubConvertUrl; + var subConvertUrl = config.ConstItem.SubConvertUrl.IsNullOrEmpty() ? Global.SubConvertUrls.FirstOrDefault() : config.ConstItem.SubConvertUrl; url = string.Format(subConvertUrl!, Utils.UrlEncode(url)); if (!url.Contains("target=")) { @@ -163,13 +163,13 @@ namespace ServiceLib.Services } } var result = await downloadHandle.TryDownloadString(url, blProxy, userAgent); - if (blProxy && Utils.IsNullOrEmpty(result)) + if (blProxy && result.IsNullOrEmpty()) { result = await downloadHandle.TryDownloadString(url, false, userAgent); } //more url - if (Utils.IsNullOrEmpty(item.ConvertTarget) && item.MoreUrl.TrimEx().IsNotEmpty()) + if (item.ConvertTarget.IsNullOrEmpty() && item.MoreUrl.TrimEx().IsNotEmpty()) { if (result.IsNotEmpty() && Utils.IsBase64String(result)) { @@ -180,13 +180,13 @@ namespace ServiceLib.Services foreach (var it in lstUrl) { var url2 = Utils.GetPunycode(it); - if (Utils.IsNullOrEmpty(url2)) + if (url2.IsNullOrEmpty()) { continue; } var result2 = await downloadHandle.TryDownloadString(url2, blProxy, userAgent); - if (blProxy && Utils.IsNullOrEmpty(result2)) + if (blProxy && result2.IsNullOrEmpty()) { result2 = await downloadHandle.TryDownloadString(url2, false, userAgent); } @@ -204,7 +204,7 @@ namespace ServiceLib.Services } } - if (Utils.IsNullOrEmpty(result)) + if (result.IsNullOrEmpty()) { _updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgSubscriptionDecodingFailed}"); } @@ -287,7 +287,7 @@ namespace ServiceLib.Services { var url = coreInfo?.ReleaseApiUrl; var result = await downloadHandle.TryDownloadString(url, true, Global.AppName); - if (Utils.IsNullOrEmpty(result)) + if (result.IsNullOrEmpty()) { return new RetResult(false, ""); } diff --git a/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs index aa796570..5acc7612 100644 --- a/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs @@ -43,13 +43,13 @@ namespace ServiceLib.ViewModels private async Task SaveServerAsync() { string remarks = SelectedSource.Remarks; - if (Utils.IsNullOrEmpty(remarks)) + if (remarks.IsNullOrEmpty()) { NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks); return; } - if (Utils.IsNullOrEmpty(SelectedSource.Address)) + if (SelectedSource.Address.IsNullOrEmpty()) { NoticeHandler.Instance.Enqueue(ResUI.FillServerAddressCustom); return; @@ -69,7 +69,7 @@ namespace ServiceLib.ViewModels public async Task BrowseServer(string fileName) { - if (Utils.IsNullOrEmpty(fileName)) + if (fileName.IsNullOrEmpty()) { return; } @@ -95,7 +95,7 @@ namespace ServiceLib.ViewModels private async Task EditServer() { var address = SelectedSource.Address; - if (Utils.IsNullOrEmpty(address)) + if (address.IsNullOrEmpty()) { NoticeHandler.Instance.Enqueue(ResUI.FillServerAddressCustom); return; diff --git a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs index bba48dd3..eae36123 100644 --- a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs @@ -41,19 +41,19 @@ namespace ServiceLib.ViewModels private async Task SaveServerAsync() { - if (Utils.IsNullOrEmpty(SelectedSource.Remarks)) + if (SelectedSource.Remarks.IsNullOrEmpty()) { NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks); return; } - if (Utils.IsNullOrEmpty(SelectedSource.Address)) + if (SelectedSource.Address.IsNullOrEmpty()) { NoticeHandler.Instance.Enqueue(ResUI.FillServerAddress); return; } var port = SelectedSource.Port.ToString(); - if (Utils.IsNullOrEmpty(port) || !Utils.IsNumeric(port) + if (port.IsNullOrEmpty() || !Utils.IsNumeric(port) || SelectedSource.Port <= 0 || SelectedSource.Port >= Global.MaxPort) { NoticeHandler.Instance.Enqueue(ResUI.FillCorrectServerPort); @@ -61,12 +61,12 @@ namespace ServiceLib.ViewModels } if (SelectedSource.ConfigType == EConfigType.Shadowsocks) { - if (Utils.IsNullOrEmpty(SelectedSource.Id)) + if (SelectedSource.Id.IsNullOrEmpty()) { NoticeHandler.Instance.Enqueue(ResUI.FillPassword); return; } - if (Utils.IsNullOrEmpty(SelectedSource.Security)) + if (SelectedSource.Security.IsNullOrEmpty()) { NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectEncryption); return; @@ -75,7 +75,7 @@ namespace ServiceLib.ViewModels if (SelectedSource.ConfigType != EConfigType.SOCKS && SelectedSource.ConfigType != EConfigType.HTTP) { - if (Utils.IsNullOrEmpty(SelectedSource.Id)) + if (SelectedSource.Id.IsNullOrEmpty()) { NoticeHandler.Instance.Enqueue(ResUI.FillUUID); return; diff --git a/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs b/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs index fddb48d7..4d54bc65 100644 --- a/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs @@ -114,7 +114,7 @@ namespace ServiceLib.ViewModels public async Task LocalRestore(string fileName) { DisplayOperationMsg(); - if (Utils.IsNullOrEmpty(fileName)) + if (fileName.IsNullOrEmpty()) { return; } @@ -164,7 +164,7 @@ namespace ServiceLib.ViewModels private async Task CreateZipFileFromDirectory(string fileName) { - if (Utils.IsNullOrEmpty(fileName)) + if (fileName.IsNullOrEmpty()) { return false; } diff --git a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs index 9fd571a6..c539abdf 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs @@ -100,7 +100,7 @@ namespace ServiceLib.ViewModels var lstModel = new List(); foreach (var item in connections ?? new()) { - var host = $"{(Utils.IsNullOrEmpty(item.metadata.host) ? item.metadata.destinationIP : item.metadata.host)}:{item.metadata.destinationPort}"; + var host = $"{(item.metadata.host.IsNullOrEmpty() ? item.metadata.destinationIP : item.metadata.host)}:{item.metadata.destinationPort}"; if (HostFilter.IsNotEmpty() && !host.Contains(HostFilter)) { continue; diff --git a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs index e5a2973a..e44220d1 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs @@ -193,7 +193,7 @@ namespace ServiceLib.ViewModels { foreach (var it in proxyGroups) { - if (Utils.IsNullOrEmpty(it.name) || !_proxies.ContainsKey(it.name)) + if (it.name.IsNullOrEmpty() || !_proxies.ContainsKey(it.name)) { continue; } @@ -256,7 +256,7 @@ namespace ServiceLib.ViewModels return; } var name = SelectedGroup?.Name; - if (Utils.IsNullOrEmpty(name)) + if (name.IsNullOrEmpty()) { return; } @@ -341,21 +341,21 @@ namespace ServiceLib.ViewModels public async Task SetActiveProxy() { - if (SelectedGroup == null || Utils.IsNullOrEmpty(SelectedGroup.Name)) + if (SelectedGroup == null || SelectedGroup.Name.IsNullOrEmpty()) { return; } - if (SelectedDetail == null || Utils.IsNullOrEmpty(SelectedDetail.Name)) + if (SelectedDetail == null || SelectedDetail.Name.IsNullOrEmpty()) { return; } var name = SelectedGroup.Name; - if (Utils.IsNullOrEmpty(name)) + if (name.IsNullOrEmpty()) { return; } var nameNode = SelectedDetail.Name; - if (Utils.IsNullOrEmpty(nameNode)) + if (nameNode.IsNullOrEmpty()) { return; } @@ -390,7 +390,7 @@ namespace ServiceLib.ViewModels await GetClashProxies(true); return; } - if (Utils.IsNullOrEmpty(result)) + if (result.IsNullOrEmpty()) { return; } diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index 295b5364..263f2315 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -421,7 +421,7 @@ namespace ServiceLib.ViewModels public async Task ScanImageResult(string fileName) { - if (Utils.IsNullOrEmpty(fileName)) + if (fileName.IsNullOrEmpty()) { return; } @@ -432,7 +432,7 @@ namespace ServiceLib.ViewModels private async Task AddScanResultAsync(string? result) { - if (Utils.IsNullOrEmpty(result)) + if (result.IsNullOrEmpty()) { NoticeHandler.Instance.Enqueue(ResUI.NoValidQRcodeFound); } diff --git a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs index 378b374c..85b01144 100644 --- a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs @@ -266,7 +266,7 @@ namespace ServiceLib.ViewModels private async Task SaveSettingAsync() { - if (Utils.IsNullOrEmpty(localPort.ToString()) || !Utils.IsNumeric(localPort.ToString()) + if (localPort.ToString().IsNullOrEmpty() || !Utils.IsNumeric(localPort.ToString()) || localPort <= 0 || localPort >= Global.MaxPort) { NoticeHandler.Instance.Enqueue(ResUI.FillLocalListeningPort); diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index b25d840d..3f9e9cf2 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -267,7 +267,7 @@ namespace ServiceLib.ViewModels public void SetSpeedTestResult(SpeedTestResult result) { - if (Utils.IsNullOrEmpty(result.IndexId)) + if (result.IndexId.IsNullOrEmpty()) { NoticeHandler.Instance.SendMessageEx(result.Delay); NoticeHandler.Instance.Enqueue(result.Delay); @@ -350,7 +350,7 @@ namespace ServiceLib.ViewModels return; } _serverFilter = ServerFilter; - if (Utils.IsNullOrEmpty(_serverFilter)) + if (_serverFilter.IsNullOrEmpty()) { RefreshServers(); } @@ -476,7 +476,7 @@ namespace ServiceLib.ViewModels public async Task EditServerAsync(EConfigType eConfigType) { - if (Utils.IsNullOrEmpty(SelectedProfile?.IndexId)) + if (string.IsNullOrEmpty(SelectedProfile?.IndexId)) { return; } @@ -557,7 +557,7 @@ namespace ServiceLib.ViewModels public async Task SetDefaultServer() { - if (Utils.IsNullOrEmpty(SelectedProfile?.IndexId)) + if (string.IsNullOrEmpty(SelectedProfile?.IndexId)) { return; } @@ -566,7 +566,7 @@ namespace ServiceLib.ViewModels public async Task SetDefaultServer(string indexId) { - if (Utils.IsNullOrEmpty(indexId)) + if (indexId.IsNullOrEmpty()) { return; } @@ -598,7 +598,7 @@ namespace ServiceLib.ViewModels { return; } - if (Utils.IsNullOrEmpty(SelectedServer.ID)) + if (SelectedServer.ID.IsNullOrEmpty()) { return; } @@ -614,7 +614,7 @@ namespace ServiceLib.ViewModels return; } var url = FmtHandler.GetShareUri(item); - if (Utils.IsNullOrEmpty(url)) + if (url.IsNullOrEmpty()) { return; } @@ -649,7 +649,7 @@ namespace ServiceLib.ViewModels public async Task SortServer(string colName) { - if (Utils.IsNullOrEmpty(colName)) + if (colName.IsNullOrEmpty()) { return; } @@ -776,7 +776,7 @@ namespace ServiceLib.ViewModels public async Task Export2ClientConfigResult(string fileName, ProfileItem item) { - if (Utils.IsNullOrEmpty(fileName)) + if (fileName.IsNullOrEmpty()) { return; } @@ -803,7 +803,7 @@ namespace ServiceLib.ViewModels foreach (var it in lstSelecteds) { var url = FmtHandler.GetShareUri(it); - if (Utils.IsNullOrEmpty(url)) + if (url.IsNullOrEmpty()) { continue; } diff --git a/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs index 76cd301c..9b27327f 100644 --- a/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs @@ -224,7 +224,7 @@ namespace ServiceLib.ViewModels private async Task SaveRoutingAsync() { string remarks = SelectedRouting.Remarks; - if (Utils.IsNullOrEmpty(remarks)) + if (remarks.IsNullOrEmpty()) { NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks); return; @@ -252,13 +252,13 @@ namespace ServiceLib.ViewModels public async Task ImportRulesFromFileAsync(string fileName) { - if (Utils.IsNullOrEmpty(fileName)) + if (fileName.IsNullOrEmpty()) { return; } var result = EmbedUtils.LoadResource(fileName); - if (Utils.IsNullOrEmpty(result)) + if (result.IsNullOrEmpty()) { return; } @@ -288,7 +288,7 @@ namespace ServiceLib.ViewModels private async Task ImportRulesFromUrl() { var url = SelectedRouting.Url; - if (Utils.IsNullOrEmpty(url)) + if (url.IsNullOrEmpty()) { NoticeHandler.Instance.Enqueue(ResUI.MsgNeedUrl); return; @@ -311,7 +311,7 @@ namespace ServiceLib.ViewModels { blReplace = true; } - if (Utils.IsNullOrEmpty(clipboardData)) + if (clipboardData.IsNullOrEmpty()) { return -1; } diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs index f0a3dcde..2be412d4 100644 --- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs @@ -301,7 +301,7 @@ namespace ServiceLib.ViewModels { return; } - if (Utils.IsNullOrEmpty(SelectedServer.ID)) + if (SelectedServer.ID.IsNullOrEmpty()) { return; } diff --git a/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs b/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs index 2bcffa6b..0c1c3d7a 100644 --- a/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs @@ -27,7 +27,7 @@ namespace ServiceLib.ViewModels private async Task SaveSubAsync() { var remarks = SelectedSource.Remarks; - if (Utils.IsNullOrEmpty(remarks)) + if (remarks.IsNullOrEmpty()) { NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks); return; diff --git a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs index 2e6c1ed2..e53c9204 100644 --- a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs @@ -272,7 +272,7 @@ namespace v2rayN.Desktop.Views cmbHeaderType.Items.Clear(); var network = cmbNetwork.SelectedItem.ToString(); - if (Utils.IsNullOrEmpty(network)) + if (network.IsNullOrEmpty()) { cmbHeaderType.Items.Add(Global.None); return; @@ -313,7 +313,7 @@ namespace v2rayN.Desktop.Views private void SetTips() { var network = cmbNetwork.SelectedItem.ToString(); - if (Utils.IsNullOrEmpty(network)) + if (network.IsNullOrEmpty()) { network = Global.DefaultNetwork; } diff --git a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs index dcb390dd..0d6e7d26 100644 --- a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs @@ -196,7 +196,7 @@ namespace v2rayN.Desktop.Views public async Task ShareServer(string url) { - if (Utils.IsNullOrEmpty(url)) + if (url.IsNullOrEmpty()) { return; } diff --git a/v2rayN/v2rayN.Desktop/Views/SubSettingWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/SubSettingWindow.axaml.cs index a12c1b33..dd504003 100644 --- a/v2rayN/v2rayN.Desktop/Views/SubSettingWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/SubSettingWindow.axaml.cs @@ -69,7 +69,7 @@ namespace v2rayN.Desktop.Views private async Task ShareSub(string url) { - if (Utils.IsNullOrEmpty(url)) + if (url.IsNullOrEmpty()) { return; } diff --git a/v2rayN/v2rayN/Handler/WindowsHandler.cs b/v2rayN/v2rayN/Handler/WindowsHandler.cs index 95404085..70c7d09d 100644 --- a/v2rayN/v2rayN/Handler/WindowsHandler.cs +++ b/v2rayN/v2rayN/Handler/WindowsHandler.cs @@ -56,7 +56,7 @@ namespace v2rayN.Handler try { var item = await ConfigHandler.GetDefaultRouting(config); - if (item == null || Utils.IsNullOrEmpty(item.CustomIcon) || !File.Exists(item.CustomIcon)) + if (item == null || item.CustomIcon.IsNullOrEmpty() || !File.Exists(item.CustomIcon)) { return null; } diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs index c29b3416..0c6999e4 100644 --- a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs @@ -267,7 +267,7 @@ namespace v2rayN.Views cmbHeaderType.Items.Clear(); var network = cmbNetwork.SelectedItem.ToString(); - if (Utils.IsNullOrEmpty(network)) + if (network.IsNullOrEmpty()) { cmbHeaderType.Items.Add(Global.None); return; @@ -308,7 +308,7 @@ namespace v2rayN.Views private void SetTips() { var network = cmbNetwork.SelectedItem.ToString(); - if (Utils.IsNullOrEmpty(network)) + if (network.IsNullOrEmpty()) { network = Global.DefaultNetwork; } diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs index e100333f..b332898a 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs @@ -234,10 +234,10 @@ namespace v2rayN.Views // continue; //} var fontFamily = glyph.Win32FamilyNames[new CultureInfo(culture)]; - if (Utils.IsNullOrEmpty(fontFamily)) + if (fontFamily.IsNullOrEmpty()) { fontFamily = glyph.Win32FamilyNames[new CultureInfo(culture2)]; - if (Utils.IsNullOrEmpty(fontFamily)) + if (fontFamily.IsNullOrEmpty()) { continue; } diff --git a/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs index d13a189b..fc292db7 100644 --- a/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs @@ -65,7 +65,7 @@ namespace v2rayN.Views private async void ShareSub(string url) { - if (Utils.IsNullOrEmpty(url)) + if (url.IsNullOrEmpty()) { return; }