19
19
20
20
using OpenQA . Selenium . Remote ;
21
21
using System ;
22
- using System . Collections ;
23
22
using System . Collections . Generic ;
24
23
using System . Globalization ;
25
24
using System . Text . Json ;
@@ -71,18 +70,12 @@ public RemoteSessionSettings(DriverOptions mustMatchDriverOptions, params Driver
71
70
/// <summary>
72
71
/// Gets a value indicating the options that must be matched by the remote end to create a session.
73
72
/// </summary>
74
- internal DriverOptions MustMatchDriverOptions
75
- {
76
- get { return this . mustMatchDriverOptions ; }
77
- }
73
+ internal DriverOptions MustMatchDriverOptions => this . mustMatchDriverOptions ;
78
74
79
75
/// <summary>
80
76
/// Gets a value indicating the number of options that may be matched by the remote end to create a session.
81
77
/// </summary>
82
- internal int FirstMatchOptionsCount
83
- {
84
- get { return this . firstMatchOptions . Count ; }
85
- }
78
+ internal int FirstMatchOptionsCount => this . firstMatchOptions . Count ;
86
79
87
80
/// <summary>
88
81
/// Gets the capability value with the specified name.
@@ -92,6 +85,7 @@ internal int FirstMatchOptionsCount
92
85
/// <exception cref="ArgumentException">
93
86
/// The specified capability name is not in the set of capabilities.
94
87
/// </exception>
88
+ /// <exception cref="ArgumentNullException">If <paramref name="capabilityName"/> is null.</exception>
95
89
public object this [ string capabilityName ]
96
90
{
97
91
get
@@ -121,18 +115,10 @@ public object this[string capabilityName]
121
115
/// </summary>
122
116
/// <param name="settingName">The name of the setting to set.</param>
123
117
/// <param name="settingValue">The value of the setting.</param>
124
- /// <remarks>
125
- /// The value to be set must be serializable to JSON for transmission
126
- /// across the wire to the remote end. To be JSON-serializable, the value
127
- /// must be a string, a numeric value, a boolean value, an object that
128
- /// implmeents <see cref="IEnumerable"/> that contains JSON-serializable
129
- /// objects, or a <see cref="Dictionary{TKey, TValue}"/> where the keys
130
- /// are strings and the values are JSON-serializable.
131
- /// </remarks>
132
118
/// <exception cref="ArgumentException">
133
- /// Thrown if the setting name is null, the empty string, or one of the
134
- /// reserved names of metadata settings; or if the setting value is not
135
- /// JSON serializable.
119
+ /// <para>If the setting name is null or empty.</para>
120
+ /// <para>-or-</para>
121
+ /// <para>If one of the reserved names of metadata settings.</para>
136
122
/// </exception>
137
123
public void AddMetadataSetting ( string settingName , object settingValue )
138
124
{
@@ -146,11 +132,6 @@ public void AddMetadataSetting(string settingName, object settingValue)
146
132
throw new ArgumentException ( string . Format ( "'{0}' is a reserved name for a metadata setting, and cannot be used as a name." , settingName ) , nameof ( settingName ) ) ;
147
133
}
148
134
149
- if ( ! this . IsJsonSerializable ( settingValue ) )
150
- {
151
- throw new ArgumentException ( "Metadata setting value must be JSON serializable." , nameof ( settingValue ) ) ;
152
- }
153
-
154
135
this . remoteMetadataSettings [ settingName ] = settingValue ;
155
136
}
156
137
@@ -161,9 +142,9 @@ public void AddMetadataSetting(string settingName, object settingValue)
161
142
/// <param name="options">The <see cref="DriverOptions"/> to add to the list of "first matched" options.</param>
162
143
public void AddFirstMatchDriverOption ( DriverOptions options )
163
144
{
164
- if ( mustMatchDriverOptions != null )
145
+ if ( this . mustMatchDriverOptions != null )
165
146
{
166
- DriverOptionsMergeResult mergeResult = mustMatchDriverOptions . GetMergeResult ( options ) ;
147
+ DriverOptionsMergeResult mergeResult = this . mustMatchDriverOptions . GetMergeResult ( options ) ;
167
148
if ( mergeResult . IsMergeConflict )
168
149
{
169
150
string msg = string . Format ( CultureInfo . InvariantCulture , "You cannot request the same capability in both must-match and first-match capabilities. You are attempting to add a first-match driver options object that defines a capability, '{0}', that is already defined in the must-match driver options." , mergeResult . MergeConflictOptionName ) ;
@@ -297,58 +278,13 @@ private IDictionary<string, object> GetAlwaysMatchOptionsAsSerializableDictionar
297
278
298
279
private List < object > GetFirstMatchOptionsAsSerializableList ( )
299
280
{
300
- List < object > optionsMatches = new List < object > ( ) ;
281
+ List < object > optionsMatches = new List < object > ( this . firstMatchOptions . Count ) ;
301
282
foreach ( DriverOptions options in this . firstMatchOptions )
302
283
{
303
284
optionsMatches . Add ( options . ToDictionary ( ) ) ;
304
285
}
305
286
306
287
return optionsMatches ;
307
288
}
308
-
309
- private bool IsJsonSerializable ( object arg )
310
- {
311
- IEnumerable argAsEnumerable = arg as IEnumerable ;
312
- IDictionary argAsDictionary = arg as IDictionary ;
313
-
314
- if ( arg is string || arg is float || arg is double || arg is int || arg is long || arg is bool || arg == null )
315
- {
316
- return true ;
317
- }
318
- else if ( argAsDictionary != null )
319
- {
320
- foreach ( object key in argAsDictionary . Keys )
321
- {
322
- if ( ! ( key is string ) )
323
- {
324
- return false ;
325
- }
326
- }
327
-
328
- foreach ( object value in argAsDictionary . Values )
329
- {
330
- if ( ! IsJsonSerializable ( value ) )
331
- {
332
- return false ;
333
- }
334
- }
335
- }
336
- else if ( argAsEnumerable != null )
337
- {
338
- foreach ( object item in argAsEnumerable )
339
- {
340
- if ( ! IsJsonSerializable ( item ) )
341
- {
342
- return false ;
343
- }
344
- }
345
- }
346
- else
347
- {
348
- return false ;
349
- }
350
-
351
- return true ;
352
- }
353
289
}
354
290
}
0 commit comments