@@ -635,40 +635,48 @@ private void CheckValue(object value)
635635 Guard . IsFalse ( this . IsArray , nameof ( value ) , "Value should not be an array." ) ;
636636 }
637637
638+ void EnsureType ( Type expectedType )
639+ {
640+ if ( expectedType != typeof ( byte ) )
641+ {
642+ throw new Exception ( $ "Value should be a { expectedType . Name } { ( this . IsArray ? " array." : "." ) } ") ;
643+ }
644+ }
645+
638646 switch ( this . DataType )
639647 {
640648 case ExifDataType . Byte :
641- Guard . IsTrue ( type == typeof ( byte ) , nameof ( value ) , $ "Value should be a byte { ( this . IsArray ? " array." : "." ) } " ) ;
649+ EnsureType ( typeof ( byte ) ) ;
642650 break ;
643651 case ExifDataType . DoubleFloat :
644- Guard . IsTrue ( type == typeof ( double ) , nameof ( value ) , $ "Value should be a double { ( this . IsArray ? " array." : "." ) } " ) ;
652+ EnsureType ( typeof ( double ) ) ;
645653 break ;
646654 case ExifDataType . Long :
647- Guard . IsTrue ( type == typeof ( uint ) , nameof ( value ) , $ "Value should be an unsigned int { ( this . IsArray ? " array." : "." ) } " ) ;
655+ EnsureType ( typeof ( uint ) ) ;
648656 break ;
649657 case ExifDataType . Rational :
650- Guard . IsTrue ( type == typeof ( Rational ) , nameof ( value ) , $ "Value should be a Rational { ( this . IsArray ? " array." : "." ) } " ) ;
658+ EnsureType ( typeof ( Rational ) ) ;
651659 break ;
652660 case ExifDataType . Short :
653- Guard . IsTrue ( type == typeof ( ushort ) , nameof ( value ) , $ "Value should be an unsigned short { ( this . IsArray ? " array." : "." ) } " ) ;
661+ EnsureType ( typeof ( ushort ) ) ;
654662 break ;
655663 case ExifDataType . SignedByte :
656- Guard . IsTrue ( type == typeof ( sbyte ) , nameof ( value ) , $ "Value should be a signed byte { ( this . IsArray ? " array." : "." ) } " ) ;
664+ EnsureType ( typeof ( sbyte ) ) ;
657665 break ;
658666 case ExifDataType . SignedLong :
659- Guard . IsTrue ( type == typeof ( int ) , nameof ( value ) , $ "Value should be an int { ( this . IsArray ? " array." : "." ) } " ) ;
667+ EnsureType ( typeof ( int ) ) ;
660668 break ;
661669 case ExifDataType . SignedRational :
662- Guard . IsTrue ( type == typeof ( SignedRational ) , nameof ( value ) , $ "Value should be a SignedRational { ( this . IsArray ? " array." : "." ) } " ) ;
670+ EnsureType ( typeof ( SignedRational ) ) ;
663671 break ;
664672 case ExifDataType . SignedShort :
665- Guard . IsTrue ( type == typeof ( short ) , nameof ( value ) , $ "Value should be a short { ( this . IsArray ? " array." : "." ) } " ) ;
673+ EnsureType ( typeof ( short ) ) ;
666674 break ;
667675 case ExifDataType . SingleFloat :
668- Guard . IsTrue ( type == typeof ( float ) , nameof ( value ) , $ "Value should be a float { ( this . IsArray ? " array." : "." ) } " ) ;
676+ EnsureType ( typeof ( float ) ) ;
669677 break ;
670678 case ExifDataType . Undefined :
671- Guard . IsTrue ( type == typeof ( byte ) , nameof ( value ) , "Value should be a byte array." ) ;
679+ EnsureType ( typeof ( byte ) ) ;
672680 break ;
673681 default :
674682 throw new NotSupportedException ( ) ;
0 commit comments