1919
2020using  OpenQA . Selenium . Remote ; 
2121using  System ; 
22- using  System . Collections ; 
2322using  System . Collections . Generic ; 
2423using  System . Globalization ; 
25- using  System . Text . Json ; 
2624
2725namespace  OpenQA . Selenium 
2826{ 
@@ -71,18 +69,12 @@ public RemoteSessionSettings(DriverOptions mustMatchDriverOptions, params Driver
7169        /// <summary> 
7270        /// Gets a value indicating the options that must be matched by the remote end to create a session. 
7371        /// </summary> 
74-         internal  DriverOptions  MustMatchDriverOptions 
75-         { 
76-             get  {  return  this . mustMatchDriverOptions ;  } 
77-         } 
72+         internal  DriverOptions  MustMatchDriverOptions  =>  this . mustMatchDriverOptions ; 
7873
7974        /// <summary> 
8075        /// Gets a value indicating the number of options that may be matched by the remote end to create a session. 
8176        /// </summary> 
82-         internal  int  FirstMatchOptionsCount 
83-         { 
84-             get  {  return  this . firstMatchOptions . Count ;  } 
85-         } 
77+         internal  int  FirstMatchOptionsCount  =>  this . firstMatchOptions . Count ; 
8678
8779        /// <summary> 
8880        /// Gets the capability value with the specified name. 
@@ -92,6 +84,7 @@ internal int FirstMatchOptionsCount
9284        /// <exception cref="ArgumentException"> 
9385        /// The specified capability name is not in the set of capabilities. 
9486        /// </exception> 
87+         /// <exception cref="ArgumentNullException">If <paramref name="capabilityName"/> is null.</exception> 
9588        public  object  this [ string  capabilityName ] 
9689        { 
9790            get 
@@ -121,18 +114,10 @@ public object this[string capabilityName]
121114        /// </summary> 
122115        /// <param name="settingName">The name of the setting to set.</param> 
123116        /// <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> 
132117        /// <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.  
118+         /// <para>If  the setting name is null  or empty.</para>  
119+         /// <para>-or-</para>  
120+         /// <para>If one of the reserved names of metadata settings.</para>  
136121        /// </exception> 
137122        public  void  AddMetadataSetting ( string  settingName ,  object  settingValue ) 
138123        { 
@@ -146,11 +131,6 @@ public void AddMetadataSetting(string settingName, object settingValue)
146131                throw  new  ArgumentException ( string . Format ( "'{0}' is a reserved name for a metadata setting, and cannot be used as a name." ,  settingName ) ,  nameof ( settingName ) ) ; 
147132            } 
148133
149-             if  ( ! this . IsJsonSerializable ( settingValue ) ) 
150-             { 
151-                 throw  new  ArgumentException ( "Metadata setting value must be JSON serializable." ,  nameof ( settingValue ) ) ; 
152-             } 
153- 
154134            this . remoteMetadataSettings [ settingName ]  =  settingValue ; 
155135        } 
156136
@@ -161,9 +141,9 @@ public void AddMetadataSetting(string settingName, object settingValue)
161141        /// <param name="options">The <see cref="DriverOptions"/> to add to the list of "first matched" options.</param> 
162142        public  void  AddFirstMatchDriverOption ( DriverOptions  options ) 
163143        { 
164-             if  ( mustMatchDriverOptions  !=  null ) 
144+             if  ( this . mustMatchDriverOptions  !=  null ) 
165145            { 
166-                 DriverOptionsMergeResult  mergeResult  =  mustMatchDriverOptions . GetMergeResult ( options ) ; 
146+                 DriverOptionsMergeResult  mergeResult  =  this . mustMatchDriverOptions . GetMergeResult ( options ) ; 
167147                if  ( mergeResult . IsMergeConflict ) 
168148                { 
169149                    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 ) ; 
@@ -271,15 +251,6 @@ public Dictionary<string, object> ToDictionary()
271251            return  capabilitiesDictionary ; 
272252        } 
273253
274-         /// <summary> 
275-         /// Return a string representation of the remote session settings to be sent. 
276-         /// </summary> 
277-         /// <returns>String representation of the remote session settings to be sent.</returns> 
278-         public  override  string  ToString ( ) 
279-         { 
280-             return  JsonSerializer . Serialize ( this . ToDictionary ( ) ,  new  JsonSerializerOptions  {  WriteIndented  =  true  } ) ; 
281-         } 
282- 
283254        internal  DriverOptions  GetFirstMatchDriverOptions ( int  firstMatchIndex ) 
284255        { 
285256            if  ( firstMatchIndex  <  0  ||  firstMatchIndex  >=  this . firstMatchOptions . Count ) 
@@ -297,58 +268,13 @@ private IDictionary<string, object> GetAlwaysMatchOptionsAsSerializableDictionar
297268
298269        private  List < object >  GetFirstMatchOptionsAsSerializableList ( ) 
299270        { 
300-             List < object >  optionsMatches  =  new  List < object > ( ) ; 
271+             List < object >  optionsMatches  =  new  List < object > ( this . firstMatchOptions . Count ) ; 
301272            foreach  ( DriverOptions  options  in  this . firstMatchOptions ) 
302273            { 
303274                optionsMatches . Add ( options . ToDictionary ( ) ) ; 
304275            } 
305276
306277            return  optionsMatches ; 
307278        } 
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-         } 
353279    } 
354280} 
0 commit comments