@@ -418,56 +418,6 @@ public static bool op_GreaterThanOrEqual(double a, T b)
418418
419419 #endregion
420420
421- #region Same type comparison operators
422-
423- public static bool op_Equality ( T a , T b )
424- {
425- return a . Equals ( b ) ;
426- }
427-
428- public static bool op_Inequality ( T a , T b )
429- {
430- return ! a . Equals ( b ) ;
431- }
432-
433- public static bool op_LessThan ( T a , T b )
434- {
435- if ( IsUnsigned )
436- {
437- return Convert . ToUInt64 ( a ) < Convert . ToUInt64 ( b ) ;
438- }
439- return Convert . ToInt64 ( a ) < Convert . ToInt64 ( b ) ;
440- }
441-
442- public static bool op_GreaterThan ( T a , T b )
443- {
444- if ( IsUnsigned )
445- {
446- return Convert . ToUInt64 ( a ) > Convert . ToUInt64 ( b ) ;
447- }
448- return Convert . ToInt64 ( a ) > Convert . ToInt64 ( b ) ;
449- }
450-
451- public static bool op_LessThanOrEqual ( T a , T b )
452- {
453- if ( IsUnsigned )
454- {
455- return Convert . ToUInt64 ( a ) <= Convert . ToUInt64 ( b ) ;
456- }
457- return Convert . ToInt64 ( a ) <= Convert . ToInt64 ( b ) ;
458- }
459-
460- public static bool op_GreaterThanOrEqual ( T a , T b )
461- {
462- if ( IsUnsigned )
463- {
464- return Convert . ToUInt64 ( a ) >= Convert . ToUInt64 ( b ) ;
465- }
466- return Convert . ToInt64 ( a ) >= Convert . ToInt64 ( b ) ;
467- }
468-
469- #endregion
470-
471421 #region String comparison operators
472422 public static bool op_Equality ( T a , string b )
473423 {
@@ -490,138 +440,84 @@ public static bool op_Inequality(string a, T b)
490440
491441 #endregion
492442
493- #region Other Enum comparison operators
494-
495- private static bool IsEnum ( object b , out Type type , out Type underlyingType , bool throwOnNull = false )
496- {
497- type = null ;
498- underlyingType = null ;
499- if ( b == null )
500- {
501- if ( throwOnNull )
502- {
503- using ( Py . GIL ( ) )
504- {
505- Exceptions . RaiseTypeError ( $ "Cannot compare { typeof ( T ) . Name } with null") ;
506- PythonException . ThrowLastAsClrException ( ) ;
507- }
508- }
509- return false ;
510- }
511-
512- type = b . GetType ( ) ;
513- if ( type . IsEnum )
514- {
515- underlyingType = type . GetEnumUnderlyingType ( ) ;
516- return true ;
517- }
518- using var _ = Py . GIL ( ) ;
519- Exceptions . RaiseTypeError ( $ "No method matched to compare { typeof ( T ) . Name } and { type . Name } ") ;
520- PythonException . ThrowLastAsClrException ( ) ;
521-
522- return false ;
523- }
443+ #region Enum comparison operators
524444
525- public static bool op_Equality ( T a , object b )
445+ public static bool op_Equality ( T a , Enum b )
526446 {
527- if ( ! IsEnum ( b , out var bType , out var underlyingType ) )
528- {
529- return false ;
530- }
531- if ( underlyingType == typeof ( UInt64 ) )
447+ if ( b . GetType ( ) . GetEnumUnderlyingType ( ) == typeof ( UInt64 ) )
532448 {
533449 return op_Equality ( a , Convert . ToUInt64 ( b ) ) ;
534450 }
535451 return op_Equality ( a , Convert . ToInt64 ( b ) ) ;
536452 }
537453
538- public static bool op_Equality ( object a , T b )
454+ public static bool op_Equality ( Enum a , T b )
539455 {
540456 return op_Equality ( b , a ) ;
541457 }
542458
543- public static bool op_Inequality ( T a , object b )
459+ public static bool op_Inequality ( T a , Enum b )
544460 {
545461 return ! op_Equality ( a , b ) ;
546462 }
547463
548- public static bool op_Inequality ( object a , T b )
464+ public static bool op_Inequality ( Enum a , T b )
549465 {
550466 return ! op_Equality ( b , a ) ;
551467 }
552468
553- public static bool op_LessThan ( T a , object b )
469+ public static bool op_LessThan ( T a , Enum b )
554470 {
555- if ( ! IsEnum ( b , out var bType , out var underlyingType , throwOnNull : true ) )
556- {
557- // False although it means nothing: an exception will be raised
558- return false ;
559- }
560- if ( underlyingType == typeof ( UInt64 ) )
471+ if ( b . GetType ( ) . GetEnumUnderlyingType ( ) == typeof ( UInt64 ) )
561472 {
562473 return op_LessThan ( a , Convert . ToUInt64 ( b ) ) ;
563474 }
564475 return op_LessThan ( a , Convert . ToInt64 ( b ) ) ;
565476 }
566477
567- public static bool op_LessThan ( object a , T b )
478+ public static bool op_LessThan ( Enum a , T b )
568479 {
569480 return op_GreaterThan ( b , a ) ;
570481 }
571482
572- public static bool op_GreaterThan ( T a , object b )
483+ public static bool op_GreaterThan ( T a , Enum b )
573484 {
574- if ( ! IsEnum ( b , out var bType , out var underlyingType , throwOnNull : true ) )
575- {
576- // False although it means nothing: an exception will be raised
577- return false ;
578- }
579- if ( underlyingType == typeof ( UInt64 ) )
485+ if ( b . GetType ( ) . GetEnumUnderlyingType ( ) == typeof ( UInt64 ) )
580486 {
581487 return op_GreaterThan ( a , Convert . ToUInt64 ( b ) ) ;
582488 }
583489 return op_GreaterThan ( a , Convert . ToInt64 ( b ) ) ;
584490 }
585491
586- public static bool op_GreaterThan ( object a , T b )
492+ public static bool op_GreaterThan ( Enum a , T b )
587493 {
588494 return op_LessThan ( b , a ) ;
589495 }
590496
591- public static bool op_LessThanOrEqual ( T a , object b )
497+ public static bool op_LessThanOrEqual ( T a , Enum b )
592498 {
593- if ( ! IsEnum ( b , out var bType , out var underlyingType , throwOnNull : true ) )
594- {
595- // False although it means nothing: an exception will be raised
596- return false ;
597- }
598- if ( underlyingType == typeof ( UInt64 ) )
499+ if ( b . GetType ( ) . GetEnumUnderlyingType ( ) == typeof ( UInt64 ) )
599500 {
600501 return op_LessThanOrEqual ( a , Convert . ToUInt64 ( b ) ) ;
601502 }
602503 return op_LessThanOrEqual ( a , Convert . ToInt64 ( b ) ) ;
603504 }
604505
605- public static bool op_LessThanOrEqual ( object a , T b )
506+ public static bool op_LessThanOrEqual ( Enum a , T b )
606507 {
607508 return op_GreaterThanOrEqual ( b , a ) ;
608509 }
609510
610- public static bool op_GreaterThanOrEqual ( T a , object b )
511+ public static bool op_GreaterThanOrEqual ( T a , Enum b )
611512 {
612- if ( ! IsEnum ( b , out var bType , out var underlyingType , throwOnNull : true ) )
613- {
614- // False although it means nothing: an exception will be raised
615- return false ;
616- }
617- if ( underlyingType == typeof ( UInt64 ) )
513+ if ( b . GetType ( ) . GetEnumUnderlyingType ( ) == typeof ( UInt64 ) )
618514 {
619515 return op_GreaterThanOrEqual ( a , Convert . ToUInt64 ( b ) ) ;
620516 }
621517 return op_GreaterThanOrEqual ( a , Convert . ToInt64 ( b ) ) ;
622518 }
623519
624- public static bool op_GreaterThanOrEqual ( object a , T b )
520+ public static bool op_GreaterThanOrEqual ( Enum a , T b )
625521 {
626522 return op_LessThanOrEqual ( b , a ) ;
627523 }
0 commit comments