Skip to content

Commit 0e0e092

Browse files
committed
[dotnet] Fix null warnings in RelativeBy by sealing the type
1 parent e69d5c5 commit 0e0e092

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

dotnet/src/webdriver/RelativeBy.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,9 @@ public class RelativeBy : By
3333
{
3434
private readonly string wrappedAtom;
3535
private readonly object root;
36-
private readonly List<object> filters = new List<object>();
36+
private readonly List<object> filters;
3737

38-
/// <summary>
39-
/// Prevents a default instance of the <see cref="RelativeBy"/> class.
40-
/// </summary>
41-
protected RelativeBy() : base()
38+
private static string GetWrappedAtom()
4239
{
4340
string atom;
4441
using (Stream atomStream = ResourceUtilities.GetResourceStream("find-elements.js", "find-elements.js"))
@@ -49,17 +46,14 @@ protected RelativeBy() : base()
4946
}
5047
}
5148

52-
wrappedAtom = string.Format(CultureInfo.InvariantCulture, "/* findElements */return ({0}).apply(null, arguments);", atom);
49+
return string.Format(CultureInfo.InvariantCulture, "/* findElements */return ({0}).apply(null, arguments);", atom);
5350
}
5451

55-
private RelativeBy(object root, List<object>? filters = null) : this()
52+
private RelativeBy(object root, List<object>? filters = null)
5653
{
54+
this.wrappedAtom = GetWrappedAtom();
5755
this.root = GetSerializableRoot(root);
58-
59-
if (filters != null)
60-
{
61-
this.filters.AddRange(filters);
62-
}
56+
this.filters = filters is null ? [] : [.. filters]; // Clone filters
6357
}
6458

6559
/// <summary>

0 commit comments

Comments
 (0)