From 7194abe29348dd54548d0fbec2da0c8698ca3d2f Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 26 Mar 2018 19:01:47 -0700 Subject: [PATCH] Omit types when infererable from the left or right hand sides --- src/ImageSharp/ColorSpaces/CieLab.cs | 2 +- .../MetaData/Profiles/Exif/ExifReader.cs | 28 +++++++------------ src/ImageSharp/PixelFormats/Argb32.cs | 2 +- .../PixelFormats/ColorBuilder{TPixel}.cs | 6 ++-- src/ImageSharp/PixelFormats/HalfTypeHelper.cs | 4 +-- .../PixelFormats/NamedColors{TPixel}.cs | 2 +- src/ImageSharp/Primitives/LongRational.cs | 4 +-- src/ImageSharp/Primitives/SignedRational.cs | 11 ++------ 8 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/CieLab.cs b/src/ImageSharp/ColorSpaces/CieLab.cs index cb08d08bf..ce5c6c118 100644 --- a/src/ImageSharp/ColorSpaces/CieLab.cs +++ b/src/ImageSharp/ColorSpaces/CieLab.cs @@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// Represents a that has L, A, B values set to zero. /// - public static readonly CieLab Empty = default(CieLab); + public static readonly CieLab Empty = default; /// /// The backing vector for SIMD support. diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs index 8a7b1f7d7..78e39d8d4 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs @@ -33,20 +33,12 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif /// /// Gets the thumbnail length in the byte stream /// - public uint ThumbnailLength - { - get; - private set; - } + public uint ThumbnailLength { get; private set; } /// /// Gets the thumbnail offset position in the byte stream /// - public uint ThumbnailOffset - { - get; - private set; - } + public uint ThumbnailOffset { get; private set; } /// /// Gets the remaining length. @@ -124,8 +116,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif int dataTypeSize = (int)ExifValue.GetSize(dataType); int length = data.Length / dataTypeSize; - TDataType[] result = new TDataType[length]; - byte[] buffer = new byte[dataTypeSize]; + var result = new TDataType[length]; + var buffer = new byte[dataTypeSize]; for (int i = 0; i < length; i++) { @@ -423,7 +415,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif { if (!this.ValidateArray(data, 8)) { - return default(double); + return default; } return BitConverter.ToDouble(data, 0); @@ -433,7 +425,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif { if (!this.ValidateArray(data, 4)) { - return default(uint); + return default; } return BitConverter.ToUInt32(data, 0); @@ -443,7 +435,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif { if (!this.ValidateArray(data, 2)) { - return default(ushort); + return default; } return BitConverter.ToUInt16(data, 0); @@ -453,7 +445,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif { if (!this.ValidateArray(data, 4)) { - return default(float); + return default; } return BitConverter.ToSingle(data, 0); @@ -491,7 +483,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif { if (!this.ValidateArray(data, 8, 4)) { - return default(SignedRational); + return default; } int numerator = BitConverter.ToInt32(data, 0); @@ -504,7 +496,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif { if (!this.ValidateArray(data, 2)) { - return default(short); + return default; } return BitConverter.ToInt16(data, 0); diff --git a/src/ImageSharp/PixelFormats/Argb32.cs b/src/ImageSharp/PixelFormats/Argb32.cs index 33294838e..dc1f3c08a 100644 --- a/src/ImageSharp/PixelFormats/Argb32.cs +++ b/src/ImageSharp/PixelFormats/Argb32.cs @@ -347,7 +347,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Pack(ref Vector3 vector) { - Vector4 value = new Vector4(vector, 1); + var value = new Vector4(vector, 1); return Pack(ref value); } diff --git a/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs b/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs index c646d804a..184928d0e 100644 --- a/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs @@ -32,8 +32,8 @@ namespace SixLabors.ImageSharp.PixelFormats throw new ArgumentException("Hexadecimal string is not in the correct format.", nameof(hex)); } - TPixel result = default(TPixel); - Rgba32 rgba = new Rgba32( + TPixel result = default; + var rgba = new Rgba32( (byte)(packedValue >> 24), (byte)(packedValue >> 16), (byte)(packedValue >> 8), @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Returns a that represents the color defined by the provided RGBA values. public static TPixel FromRGBA(byte red, byte green, byte blue, byte alpha) { - TPixel color = default(TPixel); + TPixel color = default; color.PackFromRgba32(new Rgba32(red, green, blue, alpha)); return color; } diff --git a/src/ImageSharp/PixelFormats/HalfTypeHelper.cs b/src/ImageSharp/PixelFormats/HalfTypeHelper.cs index 4d6ef0fb4..cf8b9f4a2 100644 --- a/src/ImageSharp/PixelFormats/HalfTypeHelper.cs +++ b/src/ImageSharp/PixelFormats/HalfTypeHelper.cs @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static ushort Pack(float value) { - Uif uif = new Uif { F = value }; + var uif = new Uif { F = value }; return Pack(uif.I); } @@ -113,7 +113,7 @@ namespace SixLabors.ImageSharp.PixelFormats result = ((((uint)value & 0x8000) << 16) | ((((((uint)value >> 10) & 0x1f) - 15) + 127) << 23)) | (mantissa << 13); } - Uif uif = new Uif { U = result }; + var uif = new Uif { U = result }; return uif.F; } diff --git a/src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs b/src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs index 6a2902f9b..e27bde882 100644 --- a/src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs @@ -735,7 +735,7 @@ namespace SixLabors.ImageSharp.PixelFormats private static TPixel[] GetWebSafePalette() { Rgba32[] constants = ColorConstants.WebSafeColors; - TPixel[] safe = new TPixel[constants.Length + 1]; + var safe = new TPixel[constants.Length + 1]; Span constantsBytes = constants.AsSpan().NonPortableCast(); PixelOperations.Instance.PackFromRgba32Bytes(constantsBytes, safe, constants.Length); diff --git a/src/ImageSharp/Primitives/LongRational.cs b/src/ImageSharp/Primitives/LongRational.cs index 641a1e5e5..9addf1e18 100644 --- a/src/ImageSharp/Primitives/LongRational.cs +++ b/src/ImageSharp/Primitives/LongRational.cs @@ -268,9 +268,9 @@ namespace SixLabors.ImageSharp.Primitives return this.Numerator.ToString(provider); } - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); sb.Append(this.Numerator.ToString(provider)); - sb.Append("/"); + sb.Append('/'); sb.Append(this.Denominator.ToString(provider)); return sb.ToString(); } diff --git a/src/ImageSharp/Primitives/SignedRational.cs b/src/ImageSharp/Primitives/SignedRational.cs index 955e9db5e..5cce98d03 100644 --- a/src/ImageSharp/Primitives/SignedRational.cs +++ b/src/ImageSharp/Primitives/SignedRational.cs @@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Primitives /// Whether to use the best possible precision when parsing the value. public SignedRational(double value, bool bestPrecision) { - LongRational rational = new LongRational(value, bestPrecision); + var rational = new LongRational(value, bestPrecision); this.Numerator = (int)rational.Numerator; this.Denominator = (int)rational.Denominator; @@ -129,12 +129,7 @@ namespace SixLabors.ImageSharp.Primitives /// public override bool Equals(object obj) { - if (obj is SignedRational) - { - return this.Equals((SignedRational)obj); - } - - return false; + return obj is SignedRational other && Equals(other); } /// @@ -149,7 +144,7 @@ namespace SixLabors.ImageSharp.Primitives /// public override int GetHashCode() { - LongRational self = new LongRational(this.Numerator, this.Denominator); + var self = new LongRational(this.Numerator, this.Denominator); return self.GetHashCode(); }