Replace all Utils.IsNotEmpty(variable) with variable.IsNotEmpty()

This commit is contained in:
2dust 2025-03-05 16:42:43 +08:00
parent 78fde575d7
commit f3af831cf2
33 changed files with 128 additions and 133 deletions

View file

@ -18,7 +18,7 @@ namespace ServiceLib.Common
Uri uri = new(url);
//Authorization Header
var headers = new WebHeaderCollection();
if (Utils.IsNotEmpty(uri.UserInfo))
if (uri.UserInfo.IsNotEmpty())
{
headers.Add(HttpRequestHeader.Authorization, "Basic " + Utils.Base64Encode(uri.UserInfo));
}

View file

@ -99,7 +99,7 @@ namespace ServiceLib.Common
}
try
{
if (Utils.IsNotEmpty(ignoredName) && entry.Name.Contains(ignoredName))
if (ignoredName.IsNotEmpty() && entry.Name.Contains(ignoredName))
{
continue;
}
@ -174,7 +174,7 @@ namespace ServiceLib.Common
// Get the files in the source directory and copy to the destination directory
foreach (var file in dir.GetFiles())
{
if (Utils.IsNotEmpty(ignoredName) && file.Name.Contains(ignoredName))
if (ignoredName.IsNotEmpty() && file.Name.Contains(ignoredName))
{
continue;
}

View file

@ -60,7 +60,7 @@ namespace ServiceLib.Common
var reader = new BarcodeReader();
var result = reader.Decode(bitmap);
if (result != null && Utils.IsNotEmpty(result.Text))
if (result != null && result.Text.IsNotEmpty())
{
return result.Text;
}

View file

@ -6,7 +6,7 @@ namespace ServiceLib.Common
{
public static bool IsNullOrEmpty([NotNullWhen(false)] this string? value)
{
return string.IsNullOrEmpty(value);
return string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value);
}
public static bool IsNullOrWhiteSpace([NotNullWhen(false)] this string? value)

View file

@ -363,11 +363,6 @@ namespace ServiceLib.Common
return text == "null";
}
public static bool IsNotEmpty(string? text)
{
return !string.IsNullOrEmpty(text);
}
/// <summary>
/// 验证Domain地址是否合法
/// </summary>

View file

@ -153,11 +153,11 @@ namespace ServiceLib.Handler
from ProfileItem a
left join SubItem b on a.subid = b.id
where 1=1 ";
if (Utils.IsNotEmpty(subid))
if (subid.IsNotEmpty())
{
sql += $" and a.subid = '{subid}'";
}
if (Utils.IsNotEmpty(filter))
if (filter.IsNotEmpty())
{
if (filter.Contains('\''))
{

View file

@ -22,7 +22,7 @@ namespace ServiceLib.Handler
{
Config? config = null;
var result = EmbedUtils.LoadResource(Utils.GetConfigPath(_configRes));
if (Utils.IsNotEmpty(result))
if (result.IsNotEmpty())
{
config = JsonUtils.Deserialize<Config>(result);
}
@ -858,7 +858,7 @@ namespace ServiceLib.Handler
{
return -1;
}
if (Utils.IsNotEmpty(profileItem.Security) && profileItem.Security != Global.None)
if (profileItem.Security.IsNotEmpty() && profileItem.Security != Global.None)
{
profileItem.Security = Global.None;
}
@ -897,7 +897,7 @@ namespace ServiceLib.Handler
{
profileItem.ConfigVersion = 2;
if (Utils.IsNotEmpty(profileItem.StreamSecurity))
if (profileItem.StreamSecurity.IsNotEmpty())
{
if (profileItem.StreamSecurity != Global.StreamSecurity
&& profileItem.StreamSecurity != Global.StreamSecurityReality)
@ -917,7 +917,7 @@ namespace ServiceLib.Handler
}
}
if (Utils.IsNotEmpty(profileItem.Network) && !Global.Networks.Contains(profileItem.Network))
if (profileItem.Network.IsNotEmpty() && !Global.Networks.Contains(profileItem.Network))
{
profileItem.Network = Global.DefaultNetwork;
}
@ -1091,7 +1091,7 @@ namespace ServiceLib.Handler
var subFilter = string.Empty;
//remove sub items
if (isSub && Utils.IsNotEmpty(subid))
if (isSub && subid.IsNotEmpty())
{
await RemoveServersViaSubid(config, subid, isSub);
subFilter = (await AppHandler.Instance.GetSubItem(subid))?.Filter ?? "";
@ -1122,7 +1122,7 @@ namespace ServiceLib.Handler
}
//exist sub items //filter
if (isSub && Utils.IsNotEmpty(subid) && Utils.IsNotEmpty(subFilter))
if (isSub && subid.IsNotEmpty() && subFilter.IsNotEmpty())
{
if (!Regex.IsMatch(profileItem.Remarks, subFilter))
{
@ -1185,7 +1185,7 @@ namespace ServiceLib.Handler
}
if (lstProfiles != null && lstProfiles.Count > 0)
{
if (isSub && Utils.IsNotEmpty(subid))
if (isSub && subid.IsNotEmpty())
{
await RemoveServersViaSubid(config, subid, isSub);
}
@ -1241,7 +1241,7 @@ namespace ServiceLib.Handler
return -1;
}
if (isSub && Utils.IsNotEmpty(subid))
if (isSub && subid.IsNotEmpty())
{
await RemoveServersViaSubid(config, subid, isSub);
}
@ -1266,7 +1266,7 @@ namespace ServiceLib.Handler
return -1;
}
if (isSub && Utils.IsNotEmpty(subid))
if (isSub && subid.IsNotEmpty())
{
await RemoveServersViaSubid(config, subid, isSub);
}
@ -1299,7 +1299,7 @@ namespace ServiceLib.Handler
}
List<ProfileItem>? lstOriSub = null;
ProfileItem? activeProfile = null;
if (isSub && Utils.IsNotEmpty(subid))
if (isSub && subid.IsNotEmpty())
{
lstOriSub = await AppHandler.Instance.ProfileItems(subid);
activeProfile = lstOriSub?.FirstOrDefault(t => t.IndexId == config.IndexId);

View file

@ -33,7 +33,7 @@ namespace ServiceLib.Handler
{
return result;
}
if (Utils.IsNotEmpty(fileName) && result.Data != null)
if (fileName.IsNotEmpty() && result.Data != null)
{
await File.WriteAllTextAsync(fileName, result.Data.ToString());
}

View file

@ -16,12 +16,12 @@ namespace ServiceLib.Handler.Fmt
protected static int GetStdTransport(ProfileItem item, string? securityDef, ref Dictionary<string, string> dicQuery)
{
if (Utils.IsNotEmpty(item.Flow))
if (item.Flow.IsNotEmpty())
{
dicQuery.Add("flow", item.Flow);
}
if (Utils.IsNotEmpty(item.StreamSecurity))
if (item.StreamSecurity.IsNotEmpty())
{
dicQuery.Add("security", item.StreamSecurity);
}
@ -32,27 +32,27 @@ namespace ServiceLib.Handler.Fmt
dicQuery.Add("security", securityDef);
}
}
if (Utils.IsNotEmpty(item.Sni))
if (item.Sni.IsNotEmpty())
{
dicQuery.Add("sni", item.Sni);
}
if (Utils.IsNotEmpty(item.Alpn))
if (item.Alpn.IsNotEmpty())
{
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
}
if (Utils.IsNotEmpty(item.Fingerprint))
if (item.Fingerprint.IsNotEmpty())
{
dicQuery.Add("fp", Utils.UrlEncode(item.Fingerprint));
}
if (Utils.IsNotEmpty(item.PublicKey))
if (item.PublicKey.IsNotEmpty())
{
dicQuery.Add("pbk", Utils.UrlEncode(item.PublicKey));
}
if (Utils.IsNotEmpty(item.ShortId))
if (item.ShortId.IsNotEmpty())
{
dicQuery.Add("sid", Utils.UrlEncode(item.ShortId));
}
if (Utils.IsNotEmpty(item.SpiderX))
if (item.SpiderX.IsNotEmpty())
{
dicQuery.Add("spx", Utils.UrlEncode(item.SpiderX));
}
@ -61,21 +61,21 @@ namespace ServiceLib.Handler.Fmt
dicQuery.Add("allowInsecure", "1");
}
dicQuery.Add("type", Utils.IsNotEmpty(item.Network) ? item.Network : nameof(ETransport.tcp));
dicQuery.Add("type", item.Network.IsNotEmpty() ? item.Network : nameof(ETransport.tcp));
switch (item.Network)
{
case nameof(ETransport.tcp):
dicQuery.Add("headerType", Utils.IsNotEmpty(item.HeaderType) ? item.HeaderType : Global.None);
if (Utils.IsNotEmpty(item.RequestHost))
dicQuery.Add("headerType", item.HeaderType.IsNotEmpty() ? item.HeaderType : Global.None);
if (item.RequestHost.IsNotEmpty())
{
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
}
break;
case nameof(ETransport.kcp):
dicQuery.Add("headerType", Utils.IsNotEmpty(item.HeaderType) ? item.HeaderType : Global.None);
if (Utils.IsNotEmpty(item.Path))
dicQuery.Add("headerType", item.HeaderType.IsNotEmpty() ? item.HeaderType : Global.None);
if (item.Path.IsNotEmpty())
{
dicQuery.Add("seed", Utils.UrlEncode(item.Path));
}
@ -83,30 +83,30 @@ namespace ServiceLib.Handler.Fmt
case nameof(ETransport.ws):
case nameof(ETransport.httpupgrade):
if (Utils.IsNotEmpty(item.RequestHost))
if (item.RequestHost.IsNotEmpty())
{
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
}
if (Utils.IsNotEmpty(item.Path))
if (item.Path.IsNotEmpty())
{
dicQuery.Add("path", Utils.UrlEncode(item.Path));
}
break;
case nameof(ETransport.xhttp):
if (Utils.IsNotEmpty(item.RequestHost))
if (item.RequestHost.IsNotEmpty())
{
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
}
if (Utils.IsNotEmpty(item.Path))
if (item.Path.IsNotEmpty())
{
dicQuery.Add("path", Utils.UrlEncode(item.Path));
}
if (Utils.IsNotEmpty(item.HeaderType) && Global.XhttpMode.Contains(item.HeaderType))
if (item.HeaderType.IsNotEmpty() && Global.XhttpMode.Contains(item.HeaderType))
{
dicQuery.Add("mode", Utils.UrlEncode(item.HeaderType));
}
if (Utils.IsNotEmpty(item.Extra))
if (item.Extra.IsNotEmpty())
{
dicQuery.Add("extra", Utils.UrlEncode(item.Extra));
}
@ -115,24 +115,24 @@ namespace ServiceLib.Handler.Fmt
case nameof(ETransport.http):
case nameof(ETransport.h2):
dicQuery["type"] = nameof(ETransport.http);
if (Utils.IsNotEmpty(item.RequestHost))
if (item.RequestHost.IsNotEmpty())
{
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
}
if (Utils.IsNotEmpty(item.Path))
if (item.Path.IsNotEmpty())
{
dicQuery.Add("path", Utils.UrlEncode(item.Path));
}
break;
case nameof(ETransport.quic):
dicQuery.Add("headerType", Utils.IsNotEmpty(item.HeaderType) ? item.HeaderType : Global.None);
dicQuery.Add("headerType", item.HeaderType.IsNotEmpty() ? item.HeaderType : Global.None);
dicQuery.Add("quicSecurity", Utils.UrlEncode(item.RequestHost));
dicQuery.Add("key", Utils.UrlEncode(item.Path));
break;
case nameof(ETransport.grpc):
if (Utils.IsNotEmpty(item.Path))
if (item.Path.IsNotEmpty())
{
dicQuery.Add("authority", Utils.UrlEncode(item.RequestHost));
dicQuery.Add("serviceName", Utils.UrlEncode(item.Path));

View file

@ -36,26 +36,26 @@ namespace ServiceLib.Handler.Fmt
string url = string.Empty;
string remark = string.Empty;
if (Utils.IsNotEmpty(item.Remarks))
if (item.Remarks.IsNotEmpty())
{
remark = "#" + Utils.UrlEncode(item.Remarks);
}
var dicQuery = new Dictionary<string, string>();
if (Utils.IsNotEmpty(item.Sni))
if (item.Sni.IsNotEmpty())
{
dicQuery.Add("sni", item.Sni);
}
if (Utils.IsNotEmpty(item.Alpn))
if (item.Alpn.IsNotEmpty())
{
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
}
if (Utils.IsNotEmpty(item.Path))
if (item.Path.IsNotEmpty())
{
dicQuery.Add("obfs", "salamander");
dicQuery.Add("obfs-password", Utils.UrlEncode(item.Path));
}
dicQuery.Add("insecure", item.AllowInsecure.ToLower() == "true" ? "1" : "0");
if (Utils.IsNotEmpty(item.Ports))
if (item.Ports.IsNotEmpty())
{
dicQuery.Add("mport", Utils.UrlEncode(item.Ports.Replace(':', '-')));
}

View file

@ -31,7 +31,7 @@ namespace ServiceLib.Handler.Fmt
string url = string.Empty;
string remark = string.Empty;
if (Utils.IsNotEmpty(item.Remarks))
if (item.Remarks.IsNotEmpty())
{
remark = "#" + Utils.UrlEncode(item.Remarks);
}
@ -58,7 +58,7 @@ namespace ServiceLib.Handler.Fmt
ProfileItem item = new();
var base64 = match.Groups["base64"].Value.TrimEnd('/');
var tag = match.Groups["tag"].Value;
if (Utils.IsNotEmpty(tag))
if (tag.IsNotEmpty())
{
item.Remarks = Utils.UrlDecode(tag);
}
@ -122,7 +122,7 @@ namespace ServiceLib.Handler.Fmt
{
//obfs-host exists
var obfsHost = queryParameters["plugin"]?.Split(';').FirstOrDefault(t => t.Contains("obfs-host"));
if (queryParameters["plugin"].Contains("obfs=http") && Utils.IsNotEmpty(obfsHost))
if (queryParameters["plugin"].Contains("obfs=http") && obfsHost.IsNotEmpty())
{
obfsHost = obfsHost?.Replace("obfs-host=", "");
item.Network = Global.DefaultNetwork;

View file

@ -28,7 +28,7 @@ namespace ServiceLib.Handler.Fmt
var url = string.Empty;
var remark = string.Empty;
if (Utils.IsNotEmpty(item.Remarks))
if (item.Remarks.IsNotEmpty())
{
remark = "#" + Utils.UrlEncode(item.Remarks);
}

View file

@ -33,7 +33,7 @@ namespace ServiceLib.Handler.Fmt
string url = string.Empty;
string remark = string.Empty;
if (Utils.IsNotEmpty(item.Remarks))
if (item.Remarks.IsNotEmpty())
{
remark = "#" + Utils.UrlEncode(item.Remarks);
}

View file

@ -40,16 +40,16 @@ namespace ServiceLib.Handler.Fmt
string url = string.Empty;
string remark = string.Empty;
if (Utils.IsNotEmpty(item.Remarks))
if (item.Remarks.IsNotEmpty())
{
remark = "#" + Utils.UrlEncode(item.Remarks);
}
var dicQuery = new Dictionary<string, string>();
if (Utils.IsNotEmpty(item.Sni))
if (item.Sni.IsNotEmpty())
{
dicQuery.Add("sni", item.Sni);
}
if (Utils.IsNotEmpty(item.Alpn))
if (item.Alpn.IsNotEmpty())
{
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
}

View file

@ -36,12 +36,12 @@ namespace ServiceLib.Handler.Fmt
string url = string.Empty;
string remark = string.Empty;
if (Utils.IsNotEmpty(item.Remarks))
if (item.Remarks.IsNotEmpty())
{
remark = "#" + Utils.UrlEncode(item.Remarks);
}
var dicQuery = new Dictionary<string, string>();
if (Utils.IsNotEmpty(item.Security))
if (item.Security.IsNotEmpty())
{
dicQuery.Add("encryption", item.Security);
}

View file

@ -78,12 +78,12 @@ namespace ServiceLib.Handler.Fmt
item.AlterId = vmessQRCode.aid;
item.Security = Utils.ToString(vmessQRCode.scy);
item.Security = Utils.IsNotEmpty(vmessQRCode.scy) ? vmessQRCode.scy : Global.DefaultSecurity;
if (Utils.IsNotEmpty(vmessQRCode.net))
item.Security = vmessQRCode.scy.IsNotEmpty() ? vmessQRCode.scy : Global.DefaultSecurity;
if (vmessQRCode.net.IsNotEmpty())
{
item.Network = vmessQRCode.net;
}
if (Utils.IsNotEmpty(vmessQRCode.type))
if (vmessQRCode.type.IsNotEmpty())
{
item.HeaderType = vmessQRCode.type;
}

View file

@ -37,25 +37,25 @@ namespace ServiceLib.Handler.Fmt
string url = string.Empty;
string remark = string.Empty;
if (Utils.IsNotEmpty(item.Remarks))
if (item.Remarks.IsNotEmpty())
{
remark = "#" + Utils.UrlEncode(item.Remarks);
}
var dicQuery = new Dictionary<string, string>();
if (Utils.IsNotEmpty(item.PublicKey))
if (item.PublicKey.IsNotEmpty())
{
dicQuery.Add("publickey", Utils.UrlEncode(item.PublicKey));
}
if (Utils.IsNotEmpty(item.Path))
if (item.Path.IsNotEmpty())
{
dicQuery.Add("reserved", Utils.UrlEncode(item.Path));
}
if (Utils.IsNotEmpty(item.RequestHost))
if (item.RequestHost.IsNotEmpty())
{
dicQuery.Add("address", Utils.UrlEncode(item.RequestHost));
}
if (Utils.IsNotEmpty(item.ShortId))
if (item.ShortId.IsNotEmpty())
{
dicQuery.Add("mtu", Utils.UrlEncode(item.ShortId));
}

View file

@ -36,7 +36,7 @@ namespace ServiceLib.Handler
private void IndexIdEnqueue(string indexId)
{
if (Utils.IsNotEmpty(indexId) && !_queIndexIds.Contains(indexId))
if (indexId.IsNotEmpty() && !_queIndexIds.Contains(indexId))
{
_queIndexIds.Enqueue(indexId);
}

View file

@ -117,7 +117,7 @@ namespace ServiceLib.Services.CoreConfig
if (_config.TunModeItem.EnableTun)
{
var tun = EmbedUtils.GetEmbedText(Global.ClashTunYaml);
if (Utils.IsNotEmpty(tun))
if (tun.IsNotEmpty())
{
var tunContent = YamlUtils.FromYaml<Dictionary<string, object>>(tun);
if (tunContent != null)

View file

@ -563,7 +563,7 @@ namespace ServiceLib.Services.CoreConfig
inbound.domain_strategy = Utils.IsNullOrEmpty(_config.RoutingBasicItem.DomainStrategy4Singbox) ? null : _config.RoutingBasicItem.DomainStrategy4Singbox;
var routing = await ConfigHandler.GetDefaultRouting(_config);
if (Utils.IsNotEmpty(routing.DomainStrategy4Singbox))
if (routing.DomainStrategy4Singbox.IsNotEmpty())
{
inbound.domain_strategy = routing.DomainStrategy4Singbox;
}
@ -583,7 +583,7 @@ namespace ServiceLib.Services.CoreConfig
singboxConfig.inbounds.Add(inbound3);
//auth
if (Utils.IsNotEmpty(_config.Inbound.First().User) && Utils.IsNotEmpty(_config.Inbound.First().Pass))
if (_config.Inbound.First().User.IsNotEmpty() && _config.Inbound.First().Pass.IsNotEmpty())
{
inbound3.users = new() { new() { username = _config.Inbound.First().User, password = _config.Inbound.First().Pass } };
}
@ -674,8 +674,8 @@ namespace ServiceLib.Services.CoreConfig
case EConfigType.SOCKS:
{
outbound.version = "5";
if (Utils.IsNotEmpty(node.Security)
&& Utils.IsNotEmpty(node.Id))
if (node.Security.IsNotEmpty()
&& node.Id.IsNotEmpty())
{
outbound.username = node.Security;
outbound.password = node.Id;
@ -684,8 +684,8 @@ namespace ServiceLib.Services.CoreConfig
}
case EConfigType.HTTP:
{
if (Utils.IsNotEmpty(node.Security)
&& Utils.IsNotEmpty(node.Id))
if (node.Security.IsNotEmpty()
&& node.Id.IsNotEmpty())
{
outbound.username = node.Security;
outbound.password = node.Id;
@ -719,7 +719,7 @@ namespace ServiceLib.Services.CoreConfig
{
outbound.password = node.Id;
if (Utils.IsNotEmpty(node.Path))
if (node.Path.IsNotEmpty())
{
outbound.obfs = new()
{
@ -775,7 +775,7 @@ namespace ServiceLib.Services.CoreConfig
{
try
{
if (_config.CoreBasicItem.MuxEnabled && Utils.IsNotEmpty(_config.Mux4SboxItem.Protocol))
if (_config.CoreBasicItem.MuxEnabled && _config.Mux4SboxItem.Protocol.IsNotEmpty())
{
var mux = new Multiplex4Sbox()
{
@ -801,11 +801,11 @@ namespace ServiceLib.Services.CoreConfig
if (node.StreamSecurity == Global.StreamSecurityReality || node.StreamSecurity == Global.StreamSecurity)
{
var server_name = string.Empty;
if (Utils.IsNotEmpty(node.Sni))
if (node.Sni.IsNotEmpty())
{
server_name = node.Sni;
}
else if (Utils.IsNotEmpty(node.RequestHost))
else if (node.RequestHost.IsNotEmpty())
{
server_name = Utils.String2List(node.RequestHost)?.First();
}
@ -816,7 +816,7 @@ namespace ServiceLib.Services.CoreConfig
insecure = Utils.ToBool(node.AllowInsecure.IsNullOrEmpty() ? _config.CoreBasicItem.DefAllowInsecure.ToString().ToLower() : node.AllowInsecure),
alpn = node.GetAlpn(),
};
if (Utils.IsNotEmpty(node.Fingerprint))
if (node.Fingerprint.IsNotEmpty())
{
tls.utls = new Utls4Sbox()
{
@ -878,7 +878,7 @@ namespace ServiceLib.Services.CoreConfig
case nameof(ETransport.ws):
transport.type = nameof(ETransport.ws);
transport.path = Utils.IsNullOrEmpty(node.Path) ? null : node.Path;
if (Utils.IsNotEmpty(node.RequestHost))
if (node.RequestHost.IsNotEmpty())
{
transport.headers = new()
{
@ -1085,7 +1085,7 @@ namespace ServiceLib.Services.CoreConfig
outbound = item.OutboundTag,
};
if (Utils.IsNotEmpty(item.Port))
if (item.Port.IsNotEmpty())
{
if (item.Port.Contains("-"))
{
@ -1096,7 +1096,7 @@ namespace ServiceLib.Services.CoreConfig
rule.port = new List<int> { Utils.ToInt(item.Port) };
}
}
if (Utils.IsNotEmpty(item.Network))
if (item.Network.IsNotEmpty())
{
rule.network = Utils.String2List(item.Network);
}
@ -1290,7 +1290,7 @@ namespace ServiceLib.Services.CoreConfig
});
var lstDomain = singboxConfig.outbounds
.Where(t => Utils.IsNotEmpty(t.server) && Utils.IsDomain(t.server))
.Where(t => t.server.IsNotEmpty() && Utils.IsDomain(t.server))
.Select(t => t.server)
.Distinct()
.ToList();
@ -1394,10 +1394,10 @@ namespace ServiceLib.Services.CoreConfig
List<Ruleset4Sbox> customRulesets = [];
var routing = await ConfigHandler.GetDefaultRouting(_config);
if (Utils.IsNotEmpty(routing.CustomRulesetPath4Singbox))
if (routing.CustomRulesetPath4Singbox.IsNotEmpty())
{
var result = EmbedUtils.LoadResource(routing.CustomRulesetPath4Singbox);
if (Utils.IsNotEmpty(result))
if (result.IsNotEmpty())
{
customRulesets = (JsonUtils.Deserialize<List<Ruleset4Sbox>>(result) ?? [])
.Where(t => t.tag != null)

View file

@ -465,7 +465,7 @@ namespace ServiceLib.Services.CoreConfig
v2rayConfig.inbounds.Add(inbound3);
//auth
if (Utils.IsNotEmpty(_config.Inbound.First().User) && Utils.IsNotEmpty(_config.Inbound.First().Pass))
if (_config.Inbound.First().User.IsNotEmpty() && _config.Inbound.First().Pass.IsNotEmpty())
{
inbound3.settings.auth = "password";
inbound3.settings.accounts = new List<AccountsItem4Ray> { new AccountsItem4Ray() { user = _config.Inbound.First().User, pass = _config.Inbound.First().Pass } };
@ -520,7 +520,7 @@ namespace ServiceLib.Services.CoreConfig
var routing = await ConfigHandler.GetDefaultRouting(_config);
if (routing != null)
{
if (Utils.IsNotEmpty(routing.DomainStrategy))
if (routing.DomainStrategy.IsNotEmpty())
{
v2rayConfig.routing.domainStrategy = routing.DomainStrategy;
}
@ -603,7 +603,7 @@ namespace ServiceLib.Services.CoreConfig
}
if (!hasDomainIp)
{
if (Utils.IsNotEmpty(rule.port)
if (rule.port.IsNotEmpty()
|| rule.protocol?.Count > 0
|| rule.inboundTag?.Count > 0
)
@ -714,8 +714,8 @@ namespace ServiceLib.Services.CoreConfig
serversItem.method = null;
serversItem.password = null;
if (Utils.IsNotEmpty(node.Security)
&& Utils.IsNotEmpty(node.Id))
if (node.Security.IsNotEmpty()
&& node.Id.IsNotEmpty())
{
SocksUsersItem4Ray socksUsersItem = new()
{
@ -868,11 +868,11 @@ namespace ServiceLib.Services.CoreConfig
alpn = node.GetAlpn(),
fingerprint = node.Fingerprint.IsNullOrEmpty() ? _config.CoreBasicItem.DefFingerprint : node.Fingerprint
};
if (Utils.IsNotEmpty(sni))
if (sni.IsNotEmpty())
{
tlsSettings.serverName = sni;
}
else if (Utils.IsNotEmpty(host))
else if (host.IsNotEmpty())
{
tlsSettings.serverName = Utils.String2List(host)?.First();
}
@ -918,7 +918,7 @@ namespace ServiceLib.Services.CoreConfig
type = node.HeaderType,
domain = host.IsNullOrEmpty() ? null : host
};
if (Utils.IsNotEmpty(path))
if (path.IsNotEmpty())
{
kcpSettings.seed = path;
}
@ -929,16 +929,16 @@ namespace ServiceLib.Services.CoreConfig
WsSettings4Ray wsSettings = new();
wsSettings.headers = new Headers4Ray();
if (Utils.IsNotEmpty(host))
if (host.IsNotEmpty())
{
wsSettings.host = host;
wsSettings.headers.Host = host;
}
if (Utils.IsNotEmpty(path))
if (path.IsNotEmpty())
{
wsSettings.path = path;
}
if (Utils.IsNotEmpty(useragent))
if (useragent.IsNotEmpty())
{
wsSettings.headers.UserAgent = useragent;
}
@ -949,11 +949,11 @@ namespace ServiceLib.Services.CoreConfig
case nameof(ETransport.httpupgrade):
HttpupgradeSettings4Ray httpupgradeSettings = new();
if (Utils.IsNotEmpty(path))
if (path.IsNotEmpty())
{
httpupgradeSettings.path = path;
}
if (Utils.IsNotEmpty(host))
if (host.IsNotEmpty())
{
httpupgradeSettings.host = host;
}
@ -965,19 +965,19 @@ namespace ServiceLib.Services.CoreConfig
streamSettings.network = ETransport.xhttp.ToString();
XhttpSettings4Ray xhttpSettings = new();
if (Utils.IsNotEmpty(path))
if (path.IsNotEmpty())
{
xhttpSettings.path = path;
}
if (Utils.IsNotEmpty(host))
if (host.IsNotEmpty())
{
xhttpSettings.host = host;
}
if (Utils.IsNotEmpty(node.HeaderType) && Global.XhttpMode.Contains(node.HeaderType))
if (node.HeaderType.IsNotEmpty() && Global.XhttpMode.Contains(node.HeaderType))
{
xhttpSettings.mode = node.HeaderType;
}
if (Utils.IsNotEmpty(node.Extra))
if (node.Extra.IsNotEmpty())
{
xhttpSettings.extra = JsonUtils.ParseJson(node.Extra);
}
@ -990,7 +990,7 @@ namespace ServiceLib.Services.CoreConfig
case nameof(ETransport.h2):
HttpSettings4Ray httpSettings = new();
if (Utils.IsNotEmpty(host))
if (host.IsNotEmpty())
{
httpSettings.host = Utils.String2List(host);
}
@ -1013,7 +1013,7 @@ namespace ServiceLib.Services.CoreConfig
streamSettings.quicSettings = quicsettings;
if (node.StreamSecurity == Global.StreamSecurity)
{
if (Utils.IsNotEmpty(sni))
if (sni.IsNotEmpty())
{
streamSettings.tlsSettings.serverName = sni;
}
@ -1058,7 +1058,7 @@ namespace ServiceLib.Services.CoreConfig
request = request.Replace("$requestUserAgent$", $"{useragent.AppendQuotes()}");
//Path
string pathHttp = @"/";
if (Utils.IsNotEmpty(path))
if (path.IsNotEmpty())
{
string[] arrPath = path.Split(',');
pathHttp = string.Join(",".AppendQuotes(), arrPath);
@ -1091,7 +1091,7 @@ namespace ServiceLib.Services.CoreConfig
}
//Outbound Freedom domainStrategy
if (Utils.IsNotEmpty(domainStrategy4Freedom))
if (domainStrategy4Freedom.IsNotEmpty())
{
var outbound = v2rayConfig.outbounds.FirstOrDefault(t => t is { protocol: "freedom", tag: Global.DirectTag });
if (outbound != null)
@ -1216,7 +1216,7 @@ namespace ServiceLib.Services.CoreConfig
{
//fragment proxy
if (_config.CoreBasicItem.EnableFragment
&& Utils.IsNotEmpty(v2rayConfig.outbounds.First().streamSettings?.security))
&& v2rayConfig.outbounds.First().streamSettings?.security.IsNullOrEmpty() == false)
{
var fragmentOutbound = new Outbounds4Ray
{

View file

@ -108,7 +108,7 @@ namespace ServiceLib.Services
try
{
var result1 = await DownloadStringAsync(url, blProxy, userAgent, 15);
if (Utils.IsNotEmpty(result1))
if (result1.IsNotEmpty())
{
return result1;
}
@ -126,7 +126,7 @@ namespace ServiceLib.Services
try
{
var result2 = await DownloadStringViaDownloader(url, blProxy, userAgent, 15);
if (Utils.IsNotEmpty(result2))
if (result2.IsNotEmpty())
{
return result2;
}
@ -168,7 +168,7 @@ namespace ServiceLib.Services
Uri uri = new(url);
//Authorization Header
if (Utils.IsNotEmpty(uri.UserInfo))
if (uri.UserInfo.IsNotEmpty())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Utils.Base64Encode(uri.UserInfo));
}

View file

@ -87,7 +87,7 @@ namespace ServiceLib.Services.Statistics
while (!res.CloseStatus.HasValue)
{
var result = Encoding.UTF8.GetString(buffer, 0, res.Count);
if (Utils.IsNotEmpty(result))
if (result.IsNotEmpty())
{
ParseOutput(result, out ulong up, out ulong down);

View file

@ -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) || (Utils.IsNotEmpty(subId) && item.Id != subId))
if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url) || (subId.IsNotEmpty() && item.Id != subId))
{
//_updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgNoValidSubscription}");
continue;
@ -149,7 +149,7 @@ namespace ServiceLib.Services
//one url
url = Utils.GetPunycode(url);
//convert
if (Utils.IsNotEmpty(item.ConvertTarget))
if (item.ConvertTarget.IsNotEmpty())
{
var subConvertUrl = Utils.IsNullOrEmpty(config.ConstItem.SubConvertUrl) ? Global.SubConvertUrls.FirstOrDefault() : config.ConstItem.SubConvertUrl;
url = string.Format(subConvertUrl!, Utils.UrlEncode(url));
@ -169,9 +169,9 @@ namespace ServiceLib.Services
}
//more url
if (Utils.IsNullOrEmpty(item.ConvertTarget) && Utils.IsNotEmpty(item.MoreUrl.TrimEx()))
if (Utils.IsNullOrEmpty(item.ConvertTarget) && item.MoreUrl.TrimEx().IsNotEmpty())
{
if (Utils.IsNotEmpty(result) && Utils.IsBase64String(result))
if (result.IsNotEmpty() && Utils.IsBase64String(result))
{
result = Utils.Base64Decode(result);
}
@ -190,7 +190,7 @@ namespace ServiceLib.Services
{
result2 = await downloadHandle.TryDownloadString(url2, false, userAgent);
}
if (Utils.IsNotEmpty(result2))
if (result2.IsNotEmpty())
{
if (Utils.IsBase64String(result2))
{

View file

@ -80,7 +80,7 @@ namespace ServiceLib.ViewModels
if (await ConfigHandler.AddCustomServer(_config, item, false) == 0)
{
NoticeHandler.Instance.Enqueue(ResUI.SuccessfullyImportedCustomServer);
if (Utils.IsNotEmpty(item.IndexId))
if (item.IndexId.IsNotEmpty())
{
SelectedSource = JsonUtils.DeepCopy(item);
}

View file

@ -32,7 +32,7 @@ namespace ServiceLib.ViewModels
var canEditRemove = this.WhenAnyValue(
x => x.SelectedSource,
selectedSource => selectedSource != null && Utils.IsNotEmpty(selectedSource.Id));
selectedSource => selectedSource != null && selectedSource.Id.IsNotEmpty());
this.WhenAnyValue(
x => x.AutoRefresh,

View file

@ -72,7 +72,7 @@ namespace ServiceLib.ViewModels
this.WhenAnyValue(
x => x.SelectedGroup,
y => y != null && Utils.IsNotEmpty(y.Name))
y => y != null && y.Name.IsNotEmpty())
.Subscribe(c => RefreshProxyDetails(c));
this.WhenAnyValue(
@ -219,7 +219,7 @@ namespace ServiceLib.ViewModels
continue;
}
var item = _proxyGroups.Where(t => t.Name == kv.Key).FirstOrDefault();
if (item != null && Utils.IsNotEmpty(item.Name))
if (item != null && item.Name.IsNotEmpty())
{
continue;
}

View file

@ -62,7 +62,7 @@ namespace ServiceLib.ViewModels
private async Task SaveSettingAsync()
{
if (Utils.IsNotEmpty(normalDNS))
if (normalDNS.IsNotEmpty())
{
var obj = JsonUtils.ParseJson(normalDNS);
if (obj != null && obj["servers"] != null)
@ -77,7 +77,7 @@ namespace ServiceLib.ViewModels
}
}
}
if (Utils.IsNotEmpty(normalDNS2))
if (normalDNS2.IsNotEmpty())
{
var obj2 = JsonUtils.Deserialize<Dns4Sbox>(normalDNS2);
if (obj2 == null)
@ -86,7 +86,7 @@ namespace ServiceLib.ViewModels
return;
}
}
if (Utils.IsNotEmpty(tunDNS2))
if (tunDNS2.IsNotEmpty())
{
var obj2 = JsonUtils.Deserialize<Dns4Sbox>(tunDNS2);
if (obj2 == null)

View file

@ -279,13 +279,13 @@ namespace ServiceLib.ViewModels
return;
}
if (Utils.IsNotEmpty(result.Delay))
if (result.Delay.IsNotEmpty())
{
int.TryParse(result.Delay, out var temp);
item.Delay = temp;
item.DelayVal = result.Delay ?? string.Empty;
}
if (Utils.IsNotEmpty(result.Speed))
if (result.Speed.IsNotEmpty())
{
item.SpeedVal = result.Speed ?? string.Empty;
}

View file

@ -78,8 +78,8 @@ namespace ServiceLib.ViewModels
|| SelectedSource.Ip?.Count > 0
|| SelectedSource.Protocol?.Count > 0
|| SelectedSource.Process?.Count > 0
|| Utils.IsNotEmpty(SelectedSource.Port)
|| Utils.IsNotEmpty(SelectedSource.Network);
|| SelectedSource.Port.IsNotEmpty()
|| SelectedSource.Network.IsNotEmpty();
if (!hasRule)
{

View file

@ -69,7 +69,7 @@ namespace v2rayN.Desktop.ViewModels
y => y != null && !y.IsNullOrEmpty())
.Subscribe(c =>
{
if (Utils.IsNotEmpty(CurrentLanguage) && _config.UiItem.CurrentLanguage != CurrentLanguage)
if (CurrentLanguage.IsNotEmpty() && _config.UiItem.CurrentLanguage != CurrentLanguage)
{
_config.UiItem.CurrentLanguage = CurrentLanguage;
Thread.CurrentThread.CurrentUICulture = new(CurrentLanguage);

View file

@ -11,7 +11,7 @@ namespace v2rayN.Converters
try
{
var fontFamily = AppHandler.Instance.Config.UiItem.CurrentFontFamily;
if (Utils.IsNotEmpty(fontFamily))
if (fontFamily.IsNotEmpty())
{
var fontPath = Utils.GetFontsPath();
MyFont = new FontFamily(new Uri(@$"file:///{fontPath}\"), $"./#{fontFamily}");

View file

@ -116,7 +116,7 @@ namespace v2rayN.ViewModels
y => y != null && !y.IsNullOrEmpty())
.Subscribe(c =>
{
if (Utils.IsNotEmpty(CurrentLanguage) && _config.UiItem.CurrentLanguage != CurrentLanguage)
if (CurrentLanguage.IsNotEmpty() && _config.UiItem.CurrentLanguage != CurrentLanguage)
{
_config.UiItem.CurrentLanguage = CurrentLanguage;
Thread.CurrentThread.CurrentUICulture = new(CurrentLanguage);