@@ -60,14 +60,14 @@ private Key(string value, string code, bool controlKey, bool shiftKey, bool altK
6060
6161 /// <summary>
6262 /// Gets the key value of the key represented. If the value has a printed
63- /// representation, this attribute's value is the same as the char attribute.
63+ /// representation, this attribute's value is the same as the char attribute.
6464 /// </summary>
6565 public string Value { get ; }
6666
6767 /// <summary>
6868 /// Gets the string that identifies the physical key being pressed. The value is not
69- /// affected by the current keyboard layout or modifier state, so a particular key
70- /// will always return the same value.
69+ /// affected by the current keyboard layout or modifier state, so a particular key
70+ /// will always return the same value.
7171 /// </summary>
7272 public string Code { get ; }
7373
@@ -337,23 +337,23 @@ private Key(string value, string code, bool controlKey, bool shiftKey, bool altK
337337 /// <param name="value">The key value.</param>
338338 public static Key FromChar ( char value ) => new Key ( value ) ;
339339
340- /// <summary>
341- /// Gets the value indicating whether the current object is equal to another object of the same type.
342- /// </summary>
343- /// <param name="obj">The object to compare with this object.</param>
344- /// <returns><c>True</c> if the current object is equal to the other parameter; otherwise, <c>false</c>.</returns>
345- public override bool Equals ( object ? obj )
346- {
347- return obj is Key key && Equals ( key ) ;
348- }
340+ /// <summary>
341+ /// Gets the value indicating whether the current object is equal to another object of the same type.
342+ /// </summary>
343+ /// <param name="obj">The object to compare with this object.</param>
344+ /// <returns><c>True</c> if the current object is equal to the other parameter; otherwise, <c>false</c>.</returns>
345+ public override bool Equals ( object ? obj )
346+ {
347+ return obj is Key key && Equals ( key ) ;
348+ }
349349
350350 /// <summary>
351351 /// Gets the value indicating whether the current object is equal to another object of the same type.
352352 /// </summary>
353353 /// <param name="other">A key to compare with this object.</param>
354354 /// <returns><c>True</c> if the current object is equal to the other parameter; otherwise, <c>false</c>.</returns>
355- public bool Equals ( Key ? other )
356- {
355+ public bool Equals ( Key ? other )
356+ {
357357 if ( other is null )
358358 {
359359 return false ;
@@ -365,25 +365,25 @@ public bool Equals(Key? other)
365365 ShiftKey == other . ShiftKey &&
366366 AltKey == other . AltKey &&
367367 CommandKey == other . CommandKey ;
368- }
368+ }
369369
370370 /// <summary>
371371 /// Gets hash code of this object.
372372 /// </summary>
373373 /// <returns>A hash code for the current object.</returns>
374- public override int GetHashCode ( )
375- {
376- return HashCode . Combine ( Value , Code , ControlKey , ShiftKey , AltKey , CommandKey ) ;
377- }
374+ public override int GetHashCode ( )
375+ {
376+ return HashCode . Combine ( Value , Code , ControlKey , ShiftKey , AltKey , CommandKey ) ;
377+ }
378378
379379 /// <summary>
380380 /// Gets a string that represents the current object.
381381 /// </summary>
382382 /// <returns>A string that represents the current object.</returns>
383- public override string ToString ( )
384- {
385- return Value ;
386- }
383+ public override string ToString ( )
384+ {
385+ return Value ;
386+ }
387387
388388 /// <summary>
389389 /// Gets the key with new value of Control key.
@@ -526,11 +526,14 @@ static bool IsSuitableForCombination(Key key)
526526 /// <returns>The Key instance with character value.</returns>
527527 [ return : NotNullIfNotNull ( "key" ) ]
528528 [ SuppressMessage ( "Usage" , "CA2225:Operator overloads have named alternates" , Justification = "Key should have minimal relation to KeyboardEventArgs type" ) ]
529- public static implicit operator KeyboardEventArgs ? ( Key ? key )
529+ public static implicit operator KeyboardEventArgs ( Key key )
530530 {
531531 if ( key is null )
532532 {
533- return null ;
533+ // In future the operator should support null as input.
534+ // However, NotNullIfNotNull does not work correctly with operators.
535+ // Therfore workaround is to make input non-nullable.
536+ return null ! ;
534537 }
535538
536539 return new KeyboardEventArgs
@@ -543,5 +546,5 @@ static bool IsSuitableForCombination(Key key)
543546 MetaKey = key . CommandKey
544547 } ;
545548 }
546- }
549+ }
547550}
0 commit comments