2222using System . Collections . ObjectModel ;
2323using System . Globalization ;
2424
25+ #nullable enable
26+
2527namespace OpenQA . Selenium . Internal
2628{
2729 /// <summary>
2830 /// Class to Create the capabilities of the browser you require for <see cref="IWebDriver"/>.
2931 /// If you wish to use default values use the static methods
3032 /// </summary>
31- internal class ReturnedCapabilities : ICapabilities , IHasCapabilitiesDictionary
33+ internal sealed class ReturnedCapabilities : ICapabilities , IHasCapabilitiesDictionary
3234 {
3335 private readonly Dictionary < string , object > capabilities = new Dictionary < string , object > ( ) ;
3436
@@ -43,32 +45,26 @@ public ReturnedCapabilities()
4345 /// Initializes a new instance of the <see cref="ReturnedCapabilities"/> class
4446 /// </summary>
4547 /// <param name="rawMap">Dictionary of items for the remote driver</param>
46- public ReturnedCapabilities ( Dictionary < string , object > rawMap )
48+ public ReturnedCapabilities ( Dictionary < string , object > ? rawMap )
4749 {
4850 if ( rawMap != null )
4951 {
50- foreach ( string key in rawMap . Keys )
52+ foreach ( KeyValuePair < string , object > rawItem in rawMap )
5153 {
52- this . capabilities [ key ] = rawMap [ key ] ;
54+ this . capabilities [ rawItem . Key ] = rawItem . Value ;
5355 }
5456 }
5557 }
5658
5759 /// <summary>
58- /// Gets the browser name
60+ /// Gets the browser name, or <see cref="string.Empty"/> if not specified.
5961 /// </summary>
6062 public string BrowserName
6163 {
6264 get
6365 {
64- string name = string . Empty ;
65- object capabilityValue = this . GetCapability ( CapabilityType . BrowserName ) ;
66- if ( capabilityValue != null )
67- {
68- name = capabilityValue . ToString ( ) ;
69- }
70-
71- return name ;
66+ object ? capabilityValue = this . GetCapability ( CapabilityType . BrowserName ) ;
67+ return capabilityValue ? . ToString ( ) ?? string . Empty ;
7268 }
7369 }
7470
@@ -84,30 +80,24 @@ public object this[string capabilityName]
8480 {
8581 get
8682 {
87- if ( ! this . capabilities . ContainsKey ( capabilityName ) )
83+ if ( ! this . capabilities . TryGetValue ( capabilityName , out object ? capabilityValue ) )
8884 {
8985 throw new ArgumentException ( string . Format ( CultureInfo . InvariantCulture , "The capability {0} is not present in this set of capabilities" , capabilityName ) ) ;
9086 }
9187
92- return this . capabilities [ capabilityName ] ;
88+ return capabilityValue ;
9389 }
9490 }
9591
9692 /// <summary>
9793 /// Gets the underlying Dictionary for a given set of capabilities.
9894 /// </summary>
99- IDictionary < string , object > IHasCapabilitiesDictionary . CapabilitiesDictionary
100- {
101- get { return this . CapabilitiesDictionary ; }
102- }
95+ IDictionary < string , object > IHasCapabilitiesDictionary . CapabilitiesDictionary => this . CapabilitiesDictionary ;
10396
10497 /// <summary>
10598 /// Gets the internal capabilities dictionary.
10699 /// </summary>
107- internal IDictionary < string , object > CapabilitiesDictionary
108- {
109- get { return new ReadOnlyDictionary < string , object > ( this . capabilities ) ; }
110- }
100+ internal IDictionary < string , object > CapabilitiesDictionary => new ReadOnlyDictionary < string , object > ( this . capabilities ) ;
111101
112102 /// <summary>
113103 /// Gets a value indicating whether the browser has a given capability.
@@ -125,15 +115,14 @@ public bool HasCapability(string capability)
125115 /// <param name="capability">The capability to get.</param>
126116 /// <returns>An object associated with the capability, or <see langword="null"/>
127117 /// if the capability is not set on the browser.</returns>
128- public object GetCapability ( string capability )
118+ public object ? GetCapability ( string capability )
129119 {
130- object capabilityValue = null ;
131- if ( this . capabilities . ContainsKey ( capability ) )
120+ if ( this . capabilities . TryGetValue ( capability , out object ? capabilityValue ) )
132121 {
133- capabilityValue = this . capabilities [ capability ] ;
122+ return capabilityValue ;
134123 }
135124
136- return capabilityValue ;
125+ return null ;
137126 }
138127
139128 /// <summary>
0 commit comments