Skip to content

Commit 78e068b

Browse files
committed
Support Set
1 parent 8e17566 commit 78e068b

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,24 @@ public static LocalValue ConvertFrom(object? value)
7979
case string str:
8080
return ConvertFrom(str);
8181

82+
case { } when value.GetType().GetInterfaces()
83+
.Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ISet<>)):
84+
IEnumerable set = (IEnumerable)value;
85+
86+
List<LocalValue> setValues = [];
87+
88+
foreach (var obj in set)
89+
{
90+
setValues.Add(ConvertFrom(obj));
91+
}
92+
93+
return new SetLocalValue(setValues);
94+
8295
case IDictionary dictionary:
8396
return ConvertFrom(dictionary);
8497

85-
case ISet<object?> set:
86-
return ConvertFrom(set);
87-
88-
case IList set:
89-
return ConvertFrom(set);
98+
case IList list:
99+
return ConvertFrom(list);
90100

91101
case IEnumerable enumerable:
92102
return ConvertFrom(enumerable);

dotnet/test/common/BiDi/Script/LocalValueConversionTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ public void CanConvertObjectValue()
167167
UIntNumber = 5u,
168168
Array = new int[] { 1, 2 },
169169
List = new List<string> { "a", "b" },
170-
Dictionary = new Dictionary<string, object> { { "a", 1 }, { "b", 2 } }
170+
Dictionary = new Dictionary<string, object> { { "a", 1 }, { "b", 2 } },
171+
Set = new HashSet<string> { "a", "b" }
171172
};
172173

173174
var value = LocalValue.ConvertFrom(arg);
@@ -178,6 +179,6 @@ public void CanConvertObjectValue()
178179

179180
var objValue = value as ObjectLocalValue;
180181

181-
Assert.That(objValue.Value, Has.Exactly(4).Count);
182+
Assert.That(objValue.Value, Has.Exactly(5).Count);
182183
}
183184
}

0 commit comments

Comments
 (0)