Skip to content

Commit df016dd

Browse files
committed
Bug fix
2dust#8720
1 parent 9ea8067 commit df016dd

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

v2rayN/ServiceLib/Common/Extension.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,28 @@ public static bool IsComplexType(this EConfigType configType)
9494
{
9595
return configType is EConfigType.Custom or EConfigType.PolicyGroup or EConfigType.ProxyChain;
9696
}
97+
98+
/// <summary>
99+
/// Safely adds elements from a collection to the list. Does nothing if the source is null.
100+
/// </summary>
101+
public static void AddRangeSafe<T>(this ICollection<T> destination, IEnumerable<T>? source)
102+
{
103+
ArgumentNullException.ThrowIfNull(destination);
104+
105+
if (source is null)
106+
{
107+
return;
108+
}
109+
110+
if (destination is List<T> list)
111+
{
112+
list.AddRange(source);
113+
return;
114+
}
115+
116+
foreach (var item in source)
117+
{
118+
destination.Add(item);
119+
}
120+
}
97121
}

v2rayN/ServiceLib/Manager/ActionPrecheckManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ private async Task<List<string>> ValidateGroupNode(ProfileItem item, ECoreType?
218218

219219
var childIds = new List<string>();
220220
var subItems = await ProfileGroupItemManager.GetSubChildProfileItems(group);
221-
childIds.AddRange(subItems.Select(p => p.IndexId));
222-
childIds.AddRange(Utils.String2List(group.ChildItems));
221+
childIds.AddRangeSafe(subItems.Select(p => p.IndexId));
222+
childIds.AddRangeSafe(Utils.String2List(group.ChildItems));
223223

224224
foreach (var child in childIds)
225225
{

0 commit comments

Comments
 (0)