From 1321037c52cddf958e6a48aa69f8f15739595f90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E4=BB=99=E5=A5=B3?= <me@ilyfairy.com>
Date: Fri, 17 Feb 2023 14:36:28 +0800
Subject: [PATCH 1/4] =?UTF-8?q?=E4=BC=98=E5=8C=96,=20=E6=94=B9=E6=88=90?=
 =?UTF-8?q?=E4=BD=BF=E7=94=A8=E8=AF=AD=E6=B3=95=E7=B3=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 v2rayN/v2rayN/Base/DownloaderHelper.cs | 133 +++++++--------
 v2rayN/v2rayN/Base/HttpClientHelper.cs | 157 +++++++++---------
 v2rayN/v2rayN/Base/StringEx.cs         |   2 +-
 v2rayN/v2rayN/Handler/ConfigHandler.cs |  28 ++--
 v2rayN/v2rayN/Handler/ProxySetting.cs  |   7 +-
 v2rayN/v2rayN/Handler/ShareHandler.cs  |  32 ++--
 v2rayN/v2rayN/Tool/FileManager.cs      |  59 +++----
 v2rayN/v2rayN/Tool/Utils.cs            | 215 +++++++++++--------------
 8 files changed, 281 insertions(+), 352 deletions(-)

diff --git a/v2rayN/v2rayN/Base/DownloaderHelper.cs b/v2rayN/v2rayN/Base/DownloaderHelper.cs
index 86ceac99..59879d04 100644
--- a/v2rayN/v2rayN/Base/DownloaderHelper.cs
+++ b/v2rayN/v2rayN/Base/DownloaderHelper.cs
@@ -13,7 +13,7 @@ namespace v2rayN.Base
         {
         }
 
-        public async Task<string> DownloadStringAsync(IWebProxy webProxy, string url, string? userAgent, int timeout)
+        public async Task<string?> DownloadStringAsync(IWebProxy webProxy, string url, string? userAgent, int timeout)
         {
             if (string.IsNullOrEmpty(url))
             {
@@ -23,7 +23,7 @@ namespace v2rayN.Base
             var cancellationToken = new CancellationTokenSource();
             cancellationToken.CancelAfter(timeout * 1000);
 
-            Uri uri = new Uri(url);
+            Uri uri = new(url);
             //Authorization Header
             var headers = new WebHeaderCollection();
             if (!Utils.IsNullOrEmpty(uri.UserInfo))
@@ -45,23 +45,17 @@ namespace v2rayN.Base
             };
 
             string text = string.Empty;
-            using (var downloader = new DownloadService(downloadOpt))
+            using var downloader = new DownloadService(downloadOpt);
+            downloader.DownloadFileCompleted += (sender, value) =>
             {
-                downloader.DownloadFileCompleted += (sender, value) =>
+                if (value.Error != null)
                 {
-                    if (value.Error != null)
-                    {
-                        throw new Exception(string.Format("{0}", value.Error.Message));
-                    }
-                };
-                using (var stream = await downloader.DownloadFileTaskAsync(address: url, cancellationToken: cancellationToken.Token))
-                {
-                    using (StreamReader reader = new StreamReader(stream))
-                    {
-                        text = reader.ReadToEnd();
-                    }
+                    throw new Exception(string.Format("{0}", value.Error.Message));
                 }
-            }
+            };
+            using var stream = await downloader.DownloadFileTaskAsync(address: url, cancellationToken: cancellationToken.Token);
+            using StreamReader reader = new(stream);
+            text = reader.ReadToEnd();
 
             downloadOpt = null;
 
@@ -73,7 +67,7 @@ namespace v2rayN.Base
         {
             if (string.IsNullOrEmpty(url))
             {
-                throw new ArgumentNullException("url");
+                throw new ArgumentNullException(nameof(url));
             }
 
             var cancellationToken = new CancellationTokenSource();
@@ -94,44 +88,42 @@ namespace v2rayN.Base
             int totalSecond = 0;
             var hasValue = false;
             double maxSpeed = 0;
-            using (var downloader = new DownloadService(downloadOpt))
+            using var downloader = new DownloadService(downloadOpt);
+            //downloader.DownloadStarted += (sender, value) =>
+            //{
+            //    if (progress != null)
+            //    {
+            //        progress.Report("Start download data...");
+            //    }
+            //};
+            downloader.DownloadProgressChanged += (sender, value) =>
             {
-                //downloader.DownloadStarted += (sender, value) =>
-                //{
-                //    if (progress != null)
-                //    {
-                //        progress.Report("Start download data...");
-                //    }
-                //};
-                downloader.DownloadProgressChanged += (sender, value) =>
+                TimeSpan ts = (DateTime.Now - totalDatetime);
+                if (progress != null && ts.Seconds > totalSecond)
                 {
-                    TimeSpan ts = (DateTime.Now - totalDatetime);
-                    if (progress != null && ts.Seconds > totalSecond)
+                    hasValue = true;
+                    totalSecond = ts.Seconds;
+                    if (value.BytesPerSecondSpeed > maxSpeed)
                     {
-                        hasValue = true;
-                        totalSecond = ts.Seconds;
-                        if (value.BytesPerSecondSpeed > maxSpeed)
-                        {
-                            maxSpeed = value.BytesPerSecondSpeed;
-                            var speed = (maxSpeed / 1000 / 1000).ToString("#0.0");
-                            progress.Report(speed);
-                        }
+                        maxSpeed = value.BytesPerSecondSpeed;
+                        var speed = (maxSpeed / 1000 / 1000).ToString("#0.0");
+                        progress.Report(speed);
                     }
-                };
-                downloader.DownloadFileCompleted += (sender, value) =>
+                }
+            };
+            downloader.DownloadFileCompleted += (sender, value) =>
+            {
+                if (progress != null)
                 {
-                    if (progress != null)
+                    if (!hasValue && value.Error != null)
                     {
-                        if (!hasValue && value.Error != null)
-                        {
-                            progress.Report(value.Error?.Message);
-                        }
+                        progress.Report(value.Error?.Message);
                     }
-                };
-                progress.Report("......");
+                }
+            };
+            progress.Report("......");
 
-                await downloader.DownloadFileTaskAsync(address: url, cancellationToken: cancellationToken.Token);
-            }
+            await downloader.DownloadFileTaskAsync(address: url, cancellationToken: cancellationToken.Token);
 
             downloadOpt = null;
         }
@@ -167,38 +159,33 @@ namespace v2rayN.Base
 
             var progressPercentage = 0;
             var hasValue = false;
-            using (var downloader = new DownloadService(downloadOpt))
+            using var downloader = new DownloadService(downloadOpt);
+            downloader.DownloadStarted += (sender, value) =>
             {
-                downloader.DownloadStarted += (sender, value) =>
+                progress?.Report(0);
+            };
+            downloader.DownloadProgressChanged += (sender, value) =>
+            {
+                hasValue = true;
+                var percent = (int)value.ProgressPercentage;//   Convert.ToInt32((totalRead * 1d) / (total * 1d) * 100);
+                if (progressPercentage != percent && percent % 10 == 0)
                 {
-                    if (progress != null)
-                    {
-                        progress.Report(0);
-                    }
-                };
-                downloader.DownloadProgressChanged += (sender, value) =>
+                    progressPercentage = percent;
+                    progress.Report(percent);
+                }
+            };
+            downloader.DownloadFileCompleted += (sender, value) =>
+            {
+                if (progress != null)
                 {
-                    hasValue = true;
-                    var percent = (int)value.ProgressPercentage;//   Convert.ToInt32((totalRead * 1d) / (total * 1d) * 100);
-                    if (progressPercentage != percent && percent % 10 == 0)
+                    if (hasValue && value.Error == null)
                     {
-                        progressPercentage = percent;
-                        progress.Report(percent);
+                        progress.Report(101);
                     }
-                };
-                downloader.DownloadFileCompleted += (sender, value) =>
-                {
-                    if (progress != null)
-                    {
-                        if (hasValue && value.Error == null)
-                        {
-                            progress.Report(101);
-                        }
-                    }
-                };
+                }
+            };
 
-                await downloader.DownloadFileTaskAsync(url, fileName, cancellationToken: cancellationToken.Token);
-            }
+            await downloader.DownloadFileTaskAsync(url, fileName, cancellationToken: cancellationToken.Token);
 
             downloadOpt = null;
         }
diff --git a/v2rayN/v2rayN/Base/HttpClientHelper.cs b/v2rayN/v2rayN/Base/HttpClientHelper.cs
index 4fbbc400..0c8bdab0 100644
--- a/v2rayN/v2rayN/Base/HttpClientHelper.cs
+++ b/v2rayN/v2rayN/Base/HttpClientHelper.cs
@@ -33,7 +33,7 @@ namespace v2rayN.Base
                 return httpClientHelper;
             }
         }
-        public async Task<string> GetAsync(string url)
+        public async Task<string?> GetAsync(string url)
         {
             if (string.IsNullOrEmpty(url))
             {
@@ -43,7 +43,7 @@ namespace v2rayN.Base
 
             return await response.Content.ReadAsStringAsync();
         }
-        public async Task<string> GetAsync(HttpClient client, string url, CancellationToken token)
+        public async Task<string?> GetAsync(HttpClient client, string url, CancellationToken token)
         {
             if (string.IsNullOrEmpty(url))
             {
@@ -54,7 +54,7 @@ namespace v2rayN.Base
             {
                 throw new Exception(string.Format("{0}", response.StatusCode));
             }
-            return await response.Content.ReadAsStringAsync();
+            return await response.Content.ReadAsStringAsync(token);
         }
 
         public async Task PutAsync(string url, Dictionary<string, string> headers)
@@ -92,53 +92,48 @@ namespace v2rayN.Base
             var total = response.Content.Headers.ContentLength.HasValue ? response.Content.Headers.ContentLength.Value : -1L;
             var canReportProgress = total != -1 && progress != null;
 
-            using (var stream = await response.Content.ReadAsStreamAsync())
+            using var stream = await response.Content.ReadAsStreamAsync();
+            using var file = File.Create(fileName);
+            var totalRead = 0L;
+            var buffer = new byte[1024 * 1024];
+            var isMoreToRead = true;
+            var progressPercentage = 0;
+
+            do
             {
-                using (var file = File.Create(fileName))
+                token.ThrowIfCancellationRequested();
+
+                var read = await stream.ReadAsync(buffer, 0, buffer.Length, token);
+
+                if (read == 0)
                 {
-                    var totalRead = 0L;
-                    var buffer = new byte[1024 * 1024];
-                    var isMoreToRead = true;
-                    var progressPercentage = 0;
+                    isMoreToRead = false;
+                }
+                else
+                {
+                    var data = new byte[read];
+                    buffer.ToList().CopyTo(0, data, 0, read);
 
-                    do
-                    {
-                        token.ThrowIfCancellationRequested();
+                    // TODO: put here the code to write the file to disk
+                    file.Write(data, 0, read);
 
-                        var read = await stream.ReadAsync(buffer, 0, buffer.Length, token);
+                    totalRead += read;
 
-                        if (read == 0)
-                        {
-                            isMoreToRead = false;
-                        }
-                        else
-                        {
-                            var data = new byte[read];
-                            buffer.ToList().CopyTo(0, data, 0, read);
-
-                            // TODO: put here the code to write the file to disk
-                            file.Write(data, 0, read);
-
-                            totalRead += read;
-
-                            if (canReportProgress)
-                            {
-                                var percent = Convert.ToInt32((totalRead * 1d) / (total * 1d) * 100);
-                                if (progressPercentage != percent && percent % 10 == 0)
-                                {
-                                    progressPercentage = percent;
-                                    progress.Report(percent);
-                                }
-                            }
-                        }
-                    } while (isMoreToRead);
-                    file.Close();
                     if (canReportProgress)
                     {
-                        progress.Report(101);
-
+                        var percent = Convert.ToInt32((totalRead * 1d) / (total * 1d) * 100);
+                        if (progressPercentage != percent && percent % 10 == 0)
+                        {
+                            progressPercentage = percent;
+                            progress.Report(percent);
+                        }
                     }
                 }
+            } while (isMoreToRead);
+            if (canReportProgress)
+            {
+                progress.Report(101);
+
             }
         }
 
@@ -146,7 +141,7 @@ namespace v2rayN.Base
         {
             if (string.IsNullOrEmpty(url))
             {
-                throw new ArgumentNullException("url");
+                throw new ArgumentNullException(nameof(url));
             }
 
             var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token);
@@ -159,57 +154,55 @@ namespace v2rayN.Base
             //var total = response.Content.Headers.ContentLength.HasValue ? response.Content.Headers.ContentLength.Value : -1L;
             //var canReportProgress = total != -1 && progress != null;
 
-            using (var stream = await response.Content.ReadAsStreamAsync())
+            using var stream = await response.Content.ReadAsStreamAsync(token);
+            var totalRead = 0L;
+            var buffer = new byte[1024 * 64];
+            var isMoreToRead = true;
+            string progressSpeed = string.Empty;
+            DateTime totalDatetime = DateTime.Now;
+            int totalSecond = 0;
+
+            do
             {
-                var totalRead = 0L;
-                var buffer = new byte[1024 * 64];
-                var isMoreToRead = true;
-                string progressSpeed = string.Empty;
-                DateTime totalDatetime = DateTime.Now;
-                int totalSecond = 0;
-
-                do
+                if (token.IsCancellationRequested)
                 {
-                    if (token.IsCancellationRequested)
+                    if (totalRead > 0)
                     {
-                        if (totalRead > 0)
-                        {
-                            return;
-                        }
-                        else
-                        {
-                            token.ThrowIfCancellationRequested();
-                        }
-                    }
-
-                    var read = await stream.ReadAsync(buffer, 0, buffer.Length, token);
-
-                    if (read == 0)
-                    {
-                        isMoreToRead = false;
+                        return;
                     }
                     else
                     {
-                        var data = new byte[read];
-                        buffer.ToList().CopyTo(0, data, 0, read);
+                        token.ThrowIfCancellationRequested();
+                    }
+                }
 
-                        // TODO:   
-                        totalRead += read;
+                var read = await stream.ReadAsync(buffer, 0, buffer.Length, token);
 
-                        TimeSpan ts = (DateTime.Now - totalDatetime);
-                        if (progress != null && ts.Seconds > totalSecond)
+                if (read == 0)
+                {
+                    isMoreToRead = false;
+                }
+                else
+                {
+                    var data = new byte[read];
+                    buffer.ToList().CopyTo(0, data, 0, read);
+
+                    // TODO:   
+                    totalRead += read;
+
+                    TimeSpan ts = (DateTime.Now - totalDatetime);
+                    if (progress != null && ts.Seconds > totalSecond)
+                    {
+                        totalSecond = ts.Seconds;
+                        var speed = (totalRead * 1d / ts.TotalMilliseconds / 1000).ToString("#0.0");
+                        if (progressSpeed != speed)
                         {
-                            totalSecond = ts.Seconds;
-                            var speed = (totalRead * 1d / ts.TotalMilliseconds / 1000).ToString("#0.0");
-                            if (progressSpeed != speed)
-                            {
-                                progressSpeed = speed;
-                                progress.Report(speed);
-                            }
+                            progressSpeed = speed;
+                            progress.Report(speed);
                         }
                     }
-                } while (isMoreToRead);
-            }
+                }
+            } while (isMoreToRead);
         }
 
     }
diff --git a/v2rayN/v2rayN/Base/StringEx.cs b/v2rayN/v2rayN/Base/StringEx.cs
index 8e5c8dbb..9aca7060 100644
--- a/v2rayN/v2rayN/Base/StringEx.cs
+++ b/v2rayN/v2rayN/Base/StringEx.cs
@@ -34,7 +34,7 @@ namespace v2rayN.Base
 
         public static IEnumerable<string> NonWhiteSpaceLines(this TextReader reader)
         {
-            string line;
+            string? line;
             while ((line = reader.ReadLine()) != null)
             {
                 if (line.IsWhiteSpace()) continue;
diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs
index bfe31f80..0d32390c 100644
--- a/v2rayN/v2rayN/Handler/ConfigHandler.cs
+++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs
@@ -1021,7 +1021,17 @@ namespace v2rayN.Handler
                 return -1;
             }
 
-            ProfileItem profileItem = new ProfileItem();
+            //判断str是否包含s的任意一个字符串
+            static bool Containss(string str, params string[] s)
+            {
+                foreach (var item in s)
+                {
+                    if (str.Contains(item, StringComparison.OrdinalIgnoreCase)) return true;
+                }
+                return false;
+            }
+
+            ProfileItem profileItem = new();
             //Is v2ray configuration
             V2rayConfig v2rayConfig = Utils.FromJson<V2rayConfig>(clipboardData);
             if (v2rayConfig != null
@@ -1038,9 +1048,7 @@ namespace v2rayN.Handler
                 profileItem.remarks = "v2ray_custom";
             }
             //Is Clash configuration
-            else if (clipboardData.IndexOf("port") >= 0
-                && clipboardData.IndexOf("socks-port") >= 0
-                && clipboardData.IndexOf("proxies") >= 0)
+            else if (Containss(clipboardData, "port", "socks-port", "proxies"))
             {
                 var fileName = Utils.GetTempPath($"{Utils.GetGUID(false)}.yaml");
                 File.WriteAllText(fileName, clipboardData);
@@ -1050,12 +1058,7 @@ namespace v2rayN.Handler
                 profileItem.remarks = "clash_custom";
             }
             //Is hysteria configuration
-            else if (clipboardData.IndexOf("server") >= 0
-                && clipboardData.IndexOf("up") >= 0
-                && clipboardData.IndexOf("down") >= 0
-                && clipboardData.IndexOf("listen") >= 0
-                && clipboardData.IndexOf("<html>") < 0
-                && clipboardData.IndexOf("<body>") < 0)
+            else if (Containss(clipboardData, "server", "up", "down", "listen", "<html>", "<body>"))
             {
                 var fileName = Utils.GetTempPath($"{Utils.GetGUID(false)}.json");
                 File.WriteAllText(fileName, clipboardData);
@@ -1065,10 +1068,7 @@ namespace v2rayN.Handler
                 profileItem.remarks = "hysteria_custom";
             }
             //Is naiveproxy configuration
-            else if (clipboardData.IndexOf("listen") >= 0
-                && clipboardData.IndexOf("proxy") >= 0
-                && clipboardData.IndexOf("<html>") < 0
-                && clipboardData.IndexOf("<body>") < 0)
+            else if (Containss(clipboardData, "listen", "proxy", "<html>", "<body>"))
             {
                 var fileName = Utils.GetTempPath($"{Utils.GetGUID(false)}.json");
                 File.WriteAllText(fileName, clipboardData);
diff --git a/v2rayN/v2rayN/Handler/ProxySetting.cs b/v2rayN/v2rayN/Handler/ProxySetting.cs
index 1a0d46db..045f6039 100644
--- a/v2rayN/v2rayN/Handler/ProxySetting.cs
+++ b/v2rayN/v2rayN/Handler/ProxySetting.cs
@@ -189,24 +189,21 @@ namespace v2rayN.Handler
         //判断是否使用代理
         public static bool UsedProxy()
         {
-            RegistryKey rk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
+            using RegistryKey rk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
             if (rk.GetValue("ProxyEnable").ToString() == "1")
             {
-                rk.Close();
                 return true;
             }
             else
             {
-                rk.Close();
                 return false;
             }
         }
         //获得代理的IP和端口
         public static string GetProxyProxyServer()
         {
-            RegistryKey rk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
+            using RegistryKey rk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
             string ProxyServer = rk.GetValue("ProxyServer").ToString();
-            rk.Close();
             return ProxyServer;
 
         }
diff --git a/v2rayN/v2rayN/Handler/ShareHandler.cs b/v2rayN/v2rayN/Handler/ShareHandler.cs
index 89f0647c..2b243ae3 100644
--- a/v2rayN/v2rayN/Handler/ShareHandler.cs
+++ b/v2rayN/v2rayN/Handler/ShareHandler.cs
@@ -21,28 +21,18 @@ namespace v2rayN.Handler
         {
             try
             {
-                string url = string.Empty;
+                string? url = string.Empty;
 
-                switch (item.configType)
+                url = item.configType switch
                 {
-                    case EConfigType.VMess:
-                        url = ShareVmess(item);
-                        break;
-                    case EConfigType.Shadowsocks:
-                        url = ShareShadowsocks(item);
-                        break;
-                    case EConfigType.Socks:
-                        url = ShareSocks(item);
-                        break;
-                    case EConfigType.Trojan:
-                        url = ShareTrojan(item);
-                        break;
-                    case EConfigType.VLESS:
-                        url = ShareVLESS(item);
-                        break;
-                    default:
-                        break;
-                }
+                    EConfigType.VMess => ShareVmess(item),
+                    EConfigType.Shadowsocks => ShareShadowsocks(item),
+                    EConfigType.Socks => ShareSocks(item),
+                    EConfigType.Trojan => ShareTrojan(item),
+                    EConfigType.VLESS => ShareVLESS(item),
+                    _ => null,
+                };
+                
                 return url;
             }
             catch (Exception ex)
@@ -285,7 +275,7 @@ namespace v2rayN.Handler
         {
             msg = string.Empty;
             ProfileItem profileItem = new ProfileItem();
-
+            
             try
             {
                 //载入配置文件 
diff --git a/v2rayN/v2rayN/Tool/FileManager.cs b/v2rayN/v2rayN/Tool/FileManager.cs
index c3d45263..ead61caf 100644
--- a/v2rayN/v2rayN/Tool/FileManager.cs
+++ b/v2rayN/v2rayN/Tool/FileManager.cs
@@ -10,8 +10,8 @@ namespace v2rayN.Tool
         {
             try
             {
-                using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
-                    fs.Write(content, 0, content.Length);
+                using FileStream fs = new(fileName, FileMode.Create, FileAccess.Write);
+                fs.Write(content);
                 return true;
             }
             catch (Exception ex)
@@ -20,25 +20,14 @@ namespace v2rayN.Tool
             }
             return false;
         }
-
+        
         public static void UncompressFile(string fileName, byte[] content)
         {
             try
             {
-                // Because the uncompressed size of the file is unknown,
-                // we are using an arbitrary buffer size.
-                byte[] buffer = new byte[4096];
-                int n;
-
-                using (FileStream fs = File.Create(fileName))
-                using (GZipStream input = new GZipStream(new MemoryStream(content),
-                        CompressionMode.Decompress, false))
-                {
-                    while ((n = input.Read(buffer, 0, buffer.Length)) > 0)
-                    {
-                        fs.Write(buffer, 0, n);
-                    }
-                }
+                using FileStream fs = File.Create(fileName);
+                using GZipStream input = new(new MemoryStream(content), CompressionMode.Decompress, false);
+                input.CopyTo(fs);
             }
             catch (Exception ex)
             {
@@ -55,11 +44,9 @@ namespace v2rayN.Tool
         {
             try
             {
-                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
-                using (StreamReader sr = new StreamReader(fs, encoding))
-                {
-                    return sr.ReadToEnd();
-                }
+                using FileStream fs = new(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
+                using StreamReader sr = new(fs, encoding);
+                return sr.ReadToEnd();
             }
             catch (Exception ex)
             {
@@ -71,26 +58,24 @@ namespace v2rayN.Tool
         {
             try
             {
-                using (ZipArchive archive = ZipFile.OpenRead(fileName))
+                using ZipArchive archive = ZipFile.OpenRead(fileName);
+                foreach (ZipArchiveEntry entry in archive.Entries)
                 {
-                    foreach (ZipArchiveEntry entry in archive.Entries)
+                    if (entry.Length == 0)
                     {
-                        if (entry.Length == 0)
+                        continue;
+                    }
+                    try
+                    {
+                        if (!Utils.IsNullOrEmpty(ignoredName) && entry.Name.Contains(ignoredName))
                         {
                             continue;
                         }
-                        try
-                        {
-                            if (!Utils.IsNullOrEmpty(ignoredName) && entry.Name.Contains(ignoredName))
-                            {
-                                continue;
-                            }
-                            entry.ExtractToFile(Path.Combine(toPath, entry.Name), true);
-                        }
-                        catch (IOException ex)
-                        {
-                            Utils.SaveLog(ex.Message, ex);
-                        }
+                        entry.ExtractToFile(Path.Combine(toPath, entry.Name), true);
+                    }
+                    catch (IOException ex)
+                    {
+                        Utils.SaveLog(ex.Message, ex);
                     }
                 }
             }
diff --git a/v2rayN/v2rayN/Tool/Utils.cs b/v2rayN/v2rayN/Tool/Utils.cs
index c4dbea64..70c5db62 100644
--- a/v2rayN/v2rayN/Tool/Utils.cs
+++ b/v2rayN/v2rayN/Tool/Utils.cs
@@ -48,11 +48,9 @@ namespace v2rayN
             try
             {
                 Assembly assembly = Assembly.GetExecutingAssembly();
-                using (Stream stream = assembly.GetManifestResourceStream(res))
-                using (StreamReader reader = new StreamReader(stream))
-                {
-                    result = reader.ReadToEnd();
-                }
+                using Stream stream = assembly.GetManifestResourceStream(res);
+                using StreamReader reader = new(stream);
+                result = reader.ReadToEnd();
             }
             catch (Exception ex)
             {
@@ -76,10 +74,8 @@ namespace v2rayN
                 {
                     return result;
                 }
-                using (StreamReader reader = new StreamReader(res))
-                {
-                    result = reader.ReadToEnd();
-                }
+                using StreamReader reader = new(res);
+                result = reader.ReadToEnd();
             }
             catch (Exception ex)
             {
@@ -150,20 +146,18 @@ namespace v2rayN
             int result;
             try
             {
-                using (StreamWriter file = File.CreateText(filePath))
+                using StreamWriter file = File.CreateText(filePath);
+                JsonSerializer serializer;
+                if (nullValue)
                 {
-                    JsonSerializer serializer;
-                    if (nullValue)
-                    {
-                        serializer = new JsonSerializer() { Formatting = Formatting.Indented };
-                    }
-                    else
-                    {
-                        serializer = new JsonSerializer() { Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore };
-                    }
-
-                    serializer.Serialize(file, obj);
+                    serializer = new JsonSerializer() { Formatting = Formatting.Indented };
                 }
+                else
+                {
+                    serializer = new JsonSerializer() { Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore };
+                }
+
+                serializer.Serialize(file, obj);
                 result = 0;
             }
             catch (Exception ex)
@@ -248,7 +242,7 @@ namespace v2rayN
             try
             {
                 str = str.Replace(Environment.NewLine, "");
-                List<string> list = new List<string>(str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
+                List<string> list = new(str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
                 return list.OrderBy(x => x).ToList();
             }
             catch (Exception ex)
@@ -341,7 +335,7 @@ namespace v2rayN
         {
             try
             {
-                return (obj == null ? string.Empty : obj.ToString());
+                return obj?.ToString() ?? string.Empty;
             }
             catch (Exception ex)
             {
@@ -418,10 +412,9 @@ namespace v2rayN
 
         public static string GetMD5(string str)
         {
-            var md5 = MD5.Create();
             byte[] byteOld = Encoding.UTF8.GetBytes(str);
-            byte[] byteNew = md5.ComputeHash(byteOld);
-            StringBuilder sb = new StringBuilder();
+            byte[] byteNew = MD5.HashData(byteOld);
+            StringBuilder sb = new(32);
             foreach (byte b in byteNew)
             {
                 sb.Append(b.ToString("x2"));
@@ -444,7 +437,7 @@ namespace v2rayN
             }
             try
             {
-                Uri uri = new Uri(url);
+                Uri uri = new(url);
                 if (uri.Host == uri.IdnHost)
                 {
                     return url;
@@ -572,18 +565,14 @@ namespace v2rayN
 
         public static bool IsIpv6(string ip)
         {
-            IPAddress address;
-            if (IPAddress.TryParse(ip, out address))
+            if (IPAddress.TryParse(ip, out IPAddress? address))
             {
-                switch (address.AddressFamily)
+                return address.AddressFamily switch
                 {
-                    case AddressFamily.InterNetwork:
-                        return false;
-                    case AddressFamily.InterNetworkV6:
-                        return true;
-                    default:
-                        return false;
-                }
+                    AddressFamily.InterNetwork => false,
+                    AddressFamily.InterNetworkV6 => true,
+                    _ => false,
+                };
             }
             return false;
         }
@@ -688,11 +677,11 @@ namespace v2rayN
 
         public static string RegReadValue(string path, string name, string def)
         {
-            RegistryKey regKey = null;
+            RegistryKey? regKey = null;
             try
             {
                 regKey = Registry.CurrentUser.OpenSubKey(path, false);
-                string value = regKey?.GetValue(name) as string;
+                string? value = regKey?.GetValue(name) as string;
                 if (IsNullOrEmpty(value))
                 {
                     return def;
@@ -715,7 +704,7 @@ namespace v2rayN
 
         public static void RegWriteValue(string path, string name, object value)
         {
-            RegistryKey regKey = null;
+            RegistryKey? regKey = null;
             try
             {
                 regKey = Registry.CurrentUser.CreateSubKey(path);
@@ -747,14 +736,12 @@ namespace v2rayN
         public static bool CheckForDotNetVersion(int release = 528040)
         {
             const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
-            using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey))
+            using RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey);
+            if (ndpKey != null && ndpKey.GetValue("Release") != null)
             {
-                if (ndpKey != null && ndpKey.GetValue("Release") != null)
-                {
-                    return (int)ndpKey.GetValue("Release") >= release ? true : false;
-                }
-                return false;
+                return (int)ndpKey.GetValue("Release") >= release ? true : false;
             }
+            return false;
         }
 
         /// <summary>
@@ -775,31 +762,29 @@ namespace v2rayN
             string taskDescription = description;
             string deamonFileName = fileName;
 
-            using (var taskService = new TaskService())
+            using var taskService = new TaskService();
+            var tasks = taskService.RootFolder.GetTasks(new Regex(TaskName));
+            foreach (var t in tasks)
             {
-                var tasks = taskService.RootFolder.GetTasks(new Regex(TaskName));
-                foreach (var t in tasks)
-                {
-                    taskService.RootFolder.DeleteTask(t.Name);
-                }
-                if (string.IsNullOrEmpty(fileName))
-                {
-                    return;
-                }
-
-                var task = taskService.NewTask();
-                task.RegistrationInfo.Description = taskDescription;
-                task.Settings.DisallowStartIfOnBatteries = false;
-                task.Settings.StopIfGoingOnBatteries = false;
-                task.Settings.RunOnlyIfIdle = false;
-                task.Settings.IdleSettings.StopOnIdleEnd = false;
-                task.Settings.ExecutionTimeLimit = TimeSpan.Zero;
-                task.Triggers.Add(new LogonTrigger { UserId = logonUser, Delay = TimeSpan.FromMinutes(1) });
-                task.Principal.RunLevel = TaskRunLevel.Highest;
-                task.Actions.Add(new ExecAction(deamonFileName));
-
-                taskService.RootFolder.RegisterTaskDefinition(TaskName, task);
+                taskService.RootFolder.DeleteTask(t.Name);
             }
+            if (string.IsNullOrEmpty(fileName))
+            {
+                return;
+            }
+
+            var task = taskService.NewTask();
+            task.RegistrationInfo.Description = taskDescription;
+            task.Settings.DisallowStartIfOnBatteries = false;
+            task.Settings.StopIfGoingOnBatteries = false;
+            task.Settings.RunOnlyIfIdle = false;
+            task.Settings.IdleSettings.StopOnIdleEnd = false;
+            task.Settings.ExecutionTimeLimit = TimeSpan.Zero;
+            task.Triggers.Add(new LogonTrigger { UserId = logonUser, Delay = TimeSpan.FromMinutes(1) });
+            task.Principal.RunLevel = TaskRunLevel.Highest;
+            task.Actions.Add(new ExecAction(deamonFileName));
+
+            taskService.RootFolder.RegisterTaskDefinition(TaskName, task);
         }
 
         #endregion
@@ -908,16 +893,13 @@ namespace v2rayN
         public static T DeepCopy<T>(T obj)
         {
             object retval;
-            using (MemoryStream ms = new MemoryStream())
-            {
-                BinaryFormatter bf = new BinaryFormatter();
-                //序列化成流
-                bf.Serialize(ms, obj);
-                ms.Seek(0, SeekOrigin.Begin);
-                //反序列化成对象
-                retval = bf.Deserialize(ms);
-                ms.Close();
-            }
+            MemoryStream ms = new MemoryStream();
+            BinaryFormatter bf = new BinaryFormatter();
+            //序列化成流
+            bf.Serialize(ms, obj);
+            ms.Seek(0, SeekOrigin.Begin);
+            //反序列化成对象
+            retval = bf.Deserialize(ms);
             return (T)retval;
         }
 
@@ -1075,14 +1057,11 @@ namespace v2rayN
 
         public static string UnGzip(byte[] buf)
         {
-            MemoryStream sb = new MemoryStream();
-            using (GZipStream input = new GZipStream(new MemoryStream(buf),
-            CompressionMode.Decompress,
-            false))
-            {
-                input.CopyTo(sb);
-            }
-            return Encoding.UTF8.GetString(sb.ToArray());
+            using MemoryStream sb = new();
+            using GZipStream input = new(new MemoryStream(buf), CompressionMode.Decompress, false);
+            input.CopyTo(sb);
+            sb.Position = 0;
+            return new StreamReader(sb, Encoding.UTF8).ReadToEnd();
         }
 
         public static string GetBackupPath(string filename)
@@ -1198,42 +1177,40 @@ namespace v2rayN
             {
                 foreach (Screen screen in Screen.AllScreens)
                 {
-                    using (Bitmap fullImage = new Bitmap(screen.Bounds.Width,
-                                                    screen.Bounds.Height))
+                    using Bitmap fullImage = new Bitmap(screen.Bounds.Width,
+                                                    screen.Bounds.Height);
+                    using (Graphics g = Graphics.FromImage(fullImage))
                     {
-                        using (Graphics g = Graphics.FromImage(fullImage))
+                        g.CopyFromScreen(screen.Bounds.X,
+                                         screen.Bounds.Y,
+                                         0, 0,
+                                         fullImage.Size,
+                                         CopyPixelOperation.SourceCopy);
+                    }
+                    int maxTry = 10;
+                    for (int i = 0; i < maxTry; i++)
+                    {
+                        int marginLeft = (int)((double)fullImage.Width * i / 2.5 / maxTry);
+                        int marginTop = (int)((double)fullImage.Height * i / 2.5 / maxTry);
+                        Rectangle cropRect = new Rectangle(marginLeft, marginTop, fullImage.Width - marginLeft * 2, fullImage.Height - marginTop * 2);
+                        Bitmap target = new Bitmap(screen.Bounds.Width, screen.Bounds.Height);
+
+                        double imageScale = (double)screen.Bounds.Width / (double)cropRect.Width;
+                        using (Graphics g = Graphics.FromImage(target))
                         {
-                            g.CopyFromScreen(screen.Bounds.X,
-                                             screen.Bounds.Y,
-                                             0, 0,
-                                             fullImage.Size,
-                                             CopyPixelOperation.SourceCopy);
+                            g.DrawImage(fullImage, new Rectangle(0, 0, target.Width, target.Height),
+                                            cropRect,
+                                            GraphicsUnit.Pixel);
                         }
-                        int maxTry = 10;
-                        for (int i = 0; i < maxTry; i++)
+
+                        BitmapLuminanceSource source = new BitmapLuminanceSource(target);
+                        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
+                        QRCodeReader reader = new QRCodeReader();
+                        Result result = reader.decode(bitmap);
+                        if (result != null)
                         {
-                            int marginLeft = (int)((double)fullImage.Width * i / 2.5 / maxTry);
-                            int marginTop = (int)((double)fullImage.Height * i / 2.5 / maxTry);
-                            Rectangle cropRect = new Rectangle(marginLeft, marginTop, fullImage.Width - marginLeft * 2, fullImage.Height - marginTop * 2);
-                            Bitmap target = new Bitmap(screen.Bounds.Width, screen.Bounds.Height);
-
-                            double imageScale = (double)screen.Bounds.Width / (double)cropRect.Width;
-                            using (Graphics g = Graphics.FromImage(target))
-                            {
-                                g.DrawImage(fullImage, new Rectangle(0, 0, target.Width, target.Height),
-                                                cropRect,
-                                                GraphicsUnit.Pixel);
-                            }
-
-                            BitmapLuminanceSource source = new BitmapLuminanceSource(target);
-                            BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
-                            QRCodeReader reader = new QRCodeReader();
-                            Result result = reader.decode(bitmap);
-                            if (result != null)
-                            {
-                                string ret = result.Text;
-                                return ret;
-                            }
+                            string ret = result.Text;
+                            return ret;
                         }
                     }
                 }

From fc137f9b1c29ffbf102bbdd4b40d8c2252499e8c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E4=BB=99=E5=A5=B3?= <me@ilyfairy.com>
Date: Fri, 17 Feb 2023 15:09:26 +0800
Subject: [PATCH 2/4] =?UTF-8?q?=E8=AF=AD=E5=8F=A5=E6=9B=B4=E9=80=9A?=
 =?UTF-8?q?=E9=A1=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx
index 6dd3d987..115a288f 100644
--- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx
+++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx
@@ -130,7 +130,7 @@
     <value>配置格式不正确</value>
   </data>
   <data name="CustomServerTips" xml:space="preserve">
-    <value>注意,自定义配置完全依赖您自己的配置,不能使用所有设置功能。如需使用系统代理请手工修改监听端口。</value>
+    <value>注意,自定义配置完全依赖您自己的配置,不能使用所有设置功能。如需使用系统代理请手动修改监听端口。</value>
   </data>
   <data name="Downloading" xml:space="preserve">
     <value>下载开始...</value>
@@ -148,7 +148,7 @@
     <value>生成默认配置文件失败</value>
   </data>
   <data name="FailedGetDefaultConfiguration" xml:space="preserve">
-    <value>取得默认配置失败</value>
+    <value>获取默认配置失败</value>
   </data>
   <data name="FailedImportedCustomServer" xml:space="preserve">
     <value>导入自定义配置服务器失败</value>

From a23cb95a10b2e45b1368df09313a7cd4c4c13f63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E4=BB=99=E5=A5=B3?= <me@ilyfairy.com>
Date: Fri, 17 Feb 2023 15:17:01 +0800
Subject: [PATCH 3/4] =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 v2rayN/v2rayN/Base/DownloaderHelper.cs | 14 ++++----------
 v2rayN/v2rayN/Handler/ShareHandler.cs  |  3 +--
 v2rayN/v2rayN/Tool/FileManager.cs      |  5 ++---
 v2rayN/v2rayN/Tool/Utils.cs            | 15 ++++++++-------
 4 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/v2rayN/v2rayN/Base/DownloaderHelper.cs b/v2rayN/v2rayN/Base/DownloaderHelper.cs
index 59879d04..d457dcba 100644
--- a/v2rayN/v2rayN/Base/DownloaderHelper.cs
+++ b/v2rayN/v2rayN/Base/DownloaderHelper.cs
@@ -6,13 +6,9 @@ namespace v2rayN.Base
 {
     internal class DownloaderHelper
     {
-        private static readonly Lazy<DownloaderHelper> _instance = new Lazy<DownloaderHelper>(() => new());
+        private static readonly Lazy<DownloaderHelper> _instance = new(() => new());
         public static DownloaderHelper Instance => _instance.Value;
 
-        public DownloaderHelper()
-        {
-        }
-
         public async Task<string?> DownloadStringAsync(IWebProxy webProxy, string url, string? userAgent, int timeout)
         {
             if (string.IsNullOrEmpty(url))
@@ -44,7 +40,6 @@ namespace v2rayN.Base
                 }
             };
 
-            string text = string.Empty;
             using var downloader = new DownloadService(downloadOpt);
             downloader.DownloadFileCompleted += (sender, value) =>
             {
@@ -55,11 +50,10 @@ namespace v2rayN.Base
             };
             using var stream = await downloader.DownloadFileTaskAsync(address: url, cancellationToken: cancellationToken.Token);
             using StreamReader reader = new(stream);
-            text = reader.ReadToEnd();
 
             downloadOpt = null;
 
-            return text;
+            return reader.ReadToEnd();
         }
 
 
@@ -132,11 +126,11 @@ namespace v2rayN.Base
         {
             if (string.IsNullOrEmpty(url))
             {
-                throw new ArgumentNullException("url");
+                throw new ArgumentNullException(nameof(url));
             }
             if (string.IsNullOrEmpty(fileName))
             {
-                throw new ArgumentNullException("fileName");
+                throw new ArgumentNullException(nameof(fileName));
             }
             if (File.Exists(fileName))
             {
diff --git a/v2rayN/v2rayN/Handler/ShareHandler.cs b/v2rayN/v2rayN/Handler/ShareHandler.cs
index 2b243ae3..ed93607b 100644
--- a/v2rayN/v2rayN/Handler/ShareHandler.cs
+++ b/v2rayN/v2rayN/Handler/ShareHandler.cs
@@ -268,7 +268,6 @@ namespace v2rayN.Handler
         /// <summary>
         /// 从剪贴板导入URL
         /// </summary>
-        /// <param name="fileName"></param>
         /// <param name="msg"></param>
         /// <returns></returns>
         public static ProfileItem ImportFromClipboardConfig(string clipboardData, out string msg)
@@ -626,7 +625,7 @@ namespace v2rayN.Handler
 
 
         private static readonly Regex StdVmessUserInfo = new Regex(
-            @"^(?<network>[a-z]+)(\+(?<streamSecurity>[a-z]+))?:(?<id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$");
+            @"^(?<network>[a-z]+)(\+(?<streamSecurity>[a-z]+))?:(?<id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$", RegexOptions.Compiled);
 
         private static ProfileItem ResolveSocks(string result)
         {
diff --git a/v2rayN/v2rayN/Tool/FileManager.cs b/v2rayN/v2rayN/Tool/FileManager.cs
index ead61caf..aed9f060 100644
--- a/v2rayN/v2rayN/Tool/FileManager.cs
+++ b/v2rayN/v2rayN/Tool/FileManager.cs
@@ -10,8 +10,7 @@ namespace v2rayN.Tool
         {
             try
             {
-                using FileStream fs = new(fileName, FileMode.Create, FileAccess.Write);
-                fs.Write(content);
+                File.WriteAllBytes(fileName, content);
                 return true;
             }
             catch (Exception ex)
@@ -51,7 +50,7 @@ namespace v2rayN.Tool
             catch (Exception ex)
             {
                 Utils.SaveLog(ex.Message, ex);
-                throw ex;
+                throw;
             }
         }
         public static bool ZipExtractToFile(string fileName, string toPath, string ignoredName)
diff --git a/v2rayN/v2rayN/Tool/Utils.cs b/v2rayN/v2rayN/Tool/Utils.cs
index 70c5db62..3256d38b 100644
--- a/v2rayN/v2rayN/Tool/Utils.cs
+++ b/v2rayN/v2rayN/Tool/Utils.cs
@@ -112,7 +112,7 @@ namespace v2rayN
         /// </summary>
         /// <param name="obj"></param>
         /// <returns></returns>
-        public static string ToJson(Object obj, bool indented = true)
+        public static string ToJson(object obj, bool indented = true)
         {
             string result = string.Empty;
             try
@@ -141,7 +141,7 @@ namespace v2rayN
         /// <param name="obj"></param>
         /// <param name="filePath"></param>
         /// <returns></returns>
-        public static int ToJsonFile(Object obj, string filePath, bool nullValue = true)
+        public static int ToJsonFile(object obj, string filePath, bool nullValue = true)
         {
             int result;
             try
@@ -200,11 +200,11 @@ namespace v2rayN
                 }
                 if (wrap)
                 {
-                    return string.Join("," + Environment.NewLine, lst.ToArray());
+                    return string.Join("," + Environment.NewLine, lst);
                 }
                 else
                 {
-                    return string.Join(",", lst.ToArray());
+                    return string.Join(",", lst);
                 }
             }
             catch (Exception ex)
@@ -223,7 +223,7 @@ namespace v2rayN
             try
             {
                 str = str.Replace(Environment.NewLine, "");
-                return new List<string>(str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
+                return new List<string>(str.Split(',', StringSplitOptions.RemoveEmptyEntries));
             }
             catch (Exception ex)
             {
@@ -242,8 +242,9 @@ namespace v2rayN
             try
             {
                 str = str.Replace(Environment.NewLine, "");
-                List<string> list = new(str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
-                return list.OrderBy(x => x).ToList();
+                List<string> list = new(str.Split(',', StringSplitOptions.RemoveEmptyEntries));
+                list.Sort();
+                return list;
             }
             catch (Exception ex)
             {

From b27c7fb2dd9f15d8e15ec28abb6a196239f1ad19 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E4=BB=99=E5=A5=B3?= <me@ilyfairy.com>
Date: Fri, 17 Feb 2023 22:06:17 +0800
Subject: [PATCH 4/4] =?UTF-8?q?string.Join=E7=9A=84=E7=AC=AC=E4=BA=8C?=
 =?UTF-8?q?=E4=B8=AA=E5=8F=82=E6=95=B0(List<string>)=E6=94=B9=E6=88=90ToAr?=
 =?UTF-8?q?ray?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 v2rayN/v2rayN/Tool/Utils.cs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/v2rayN/v2rayN/Tool/Utils.cs b/v2rayN/v2rayN/Tool/Utils.cs
index 3256d38b..43359be6 100644
--- a/v2rayN/v2rayN/Tool/Utils.cs
+++ b/v2rayN/v2rayN/Tool/Utils.cs
@@ -204,7 +204,7 @@ namespace v2rayN
                 }
                 else
                 {
-                    return string.Join(",", lst);
+                    return string.Join(",", lst.ToArray());
                 }
             }
             catch (Exception ex)