1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 03:25:41 +00:00

(#14) Use explicit type where non-evident

This commit is contained in:
Oliver Booth 2022-02-14 15:45:28 +00:00
parent 3a42b4cac9
commit a73ec546d1
13 changed files with 53 additions and 52 deletions

View File

@ -22,7 +22,7 @@
throw new ArgumentNullException(nameof(value));
}
var count = value.Count;
int count = value.Count;
chunkSize = chunkSize.Clamp(1, count);
for (var i = 0; i < count / chunkSize; i++)

View File

@ -1,4 +1,4 @@
using System;
using System;
namespace X10D
{
@ -70,8 +70,8 @@ namespace X10D
var last = value.LastDayOfMonth();
var lastDayOfWeek = last.DayOfWeek;
var diff = dayOfWeek - lastDayOfWeek;
var offset = diff > 0 ? diff - 7 : diff;
int diff = dayOfWeek - lastDayOfWeek;
int offset = diff > 0 ? diff - 7 : diff;
return last.AddDays(offset);
}
@ -83,7 +83,7 @@ namespace X10D
/// <returns>A <see cref="DateTimeOffset" /> representing the last day of the current month.</returns>
public static DateTimeOffset LastDayOfMonth(this DateTimeOffset value)
{
var daysInMonth = DateTime.DaysInMonth(value.Year, value.Month);
int daysInMonth = DateTime.DaysInMonth(value.Year, value.Month);
return new DateTime(value.Year, value.Month, daysInMonth);
}
@ -95,7 +95,7 @@ namespace X10D
/// <returns>A <see cref="DateTimeOffset" /> representing the next occurence of <paramref name="dayOfWeek" />.</returns>
public static DateTimeOffset Next(this DateTimeOffset value, DayOfWeek dayOfWeek)
{
var offsetDays = dayOfWeek - value.DayOfWeek;
int offsetDays = dayOfWeek - value.DayOfWeek;
if (offsetDays <= 0)
{

View File

@ -1,4 +1,4 @@
using System.Web;
using System.Web;
namespace X10D
{
@ -44,6 +44,7 @@ namespace X10D
// ReSharper disable once UseDeconstruction
// .NET Standard 2.0 does not support tuple deconstruct for KeyValuePair<K, V>
// ReSharper disable once LoopCanBeConvertedToQuery
foreach (var pair in value)
{
list.Add($"{pair.Key}={SanitizeValue(pair.Value?.ToString())}");
@ -69,8 +70,8 @@ namespace X10D
static string Sanitize(KeyValuePair<TKey, TValue> pair)
{
var key = HttpUtility.UrlEncode(pair.Key?.ToString());
var value = HttpUtility.UrlEncode(pair.Value?.ToString());
string? key = HttpUtility.UrlEncode(pair.Key?.ToString());
string? value = HttpUtility.UrlEncode(pair.Value?.ToString());
return $"{key}={value}";
}

View File

@ -24,7 +24,7 @@ namespace X10D
where T : struct, Enum
{
var array = (T[])Enum.GetValues(source.GetType());
var index = Array.IndexOf(array, source) + 1;
int index = Array.IndexOf(array, source) + 1;
return array.Length == index ? array[wrap ? 0 : index - 1] : array[index];
}
@ -45,7 +45,7 @@ namespace X10D
where T : struct, Enum
{
var array = (T[])Enum.GetValues(source.GetType());
var index = Array.IndexOf(array, source) - 1;
int index = Array.IndexOf(array, source) - 1;
return index < 0 ? array[wrap ? array.Length - 1 : 0] : array[index];
}
}

View File

@ -28,7 +28,7 @@ namespace X10D
pattern |= 1 << (32 - i);
}
var cache = value & pattern;
int cache = value & pattern;
cache >>= 32 - shift;
return (value << shift) | cache;
}
@ -54,7 +54,7 @@ namespace X10D
pattern |= 1 << i;
}
var cache = value & pattern;
int cache = value & pattern;
cache <<= 32 - shift;
return (value >> shift) | cache;
}

View File

@ -1,4 +1,4 @@
namespace X10D
namespace X10D
{
/// <summary>
/// Extension methods for <see cref="IList{T}" /> and <see cref="IReadOnlyList{T}" />.
@ -49,10 +49,10 @@
random ??= RandomExtensions.Random;
var count = source.Count;
int count = source.Count;
while (count > 0)
{
var index = random.Next(count--);
int index = random.Next(count--);
var temp = source[count];
source[count] = source[index];
source[index] = temp;

View File

@ -258,7 +258,7 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(maxValue), ExceptionMessages.MaxValueGreaterThanEqualToMinValue);
}
var sample = random.NextInt64();
long sample = random.NextInt64();
return (sample % (maxValue - minValue)) + minValue;
}

View File

@ -20,12 +20,12 @@ namespace X10D.SystemNumerics
throw new ArgumentNullException(nameof(random));
}
var seed = random.Next();
int seed = random.Next();
var seededRandom = new Random(seed);
var x = seededRandom.NextSingle(0, 360);
var y = seededRandom.NextSingle(0, 360);
var z = seededRandom.NextSingle(0, 360);
float x = seededRandom.NextSingle(0, 360);
float y = seededRandom.NextSingle(0, 360);
float z = seededRandom.NextSingle(0, 360);
return Quaternion.CreateFromYawPitchRoll(y, x, z);
}
@ -43,7 +43,7 @@ namespace X10D.SystemNumerics
throw new ArgumentNullException(nameof(random));
}
var seed = random.Next();
int seed = random.Next();
var seededRandom = new Random(seed);
float normal, w, x, y, z;
@ -76,18 +76,18 @@ namespace X10D.SystemNumerics
throw new ArgumentNullException(nameof(random));
}
var seed = random.Next();
int seed = random.Next();
var seededRandom = new Random(seed);
var angle = seededRandom.NextSingle(0, 360).DegreesToRadians();
var x = MathF.Cos(angle);
var y = MathF.Sin(angle);
float angle = seededRandom.NextSingle(0, 360).DegreesToRadians();
float x = MathF.Cos(angle);
float y = MathF.Sin(angle);
return new Vector2(x, y);
}
/// <summary>
/// Returns a <see cref="Vector3" /> with magnitude 1 whose components indicate a random point on the unit sphere.
/// Returns a <see cref="Vector3" /> with magnitude 1 whose components indicate a random point on the unit sphere.
/// </summary>
/// <param name="random">The <see cref="System.Random" /> instance</param>
/// <returns>
@ -101,7 +101,7 @@ namespace X10D.SystemNumerics
throw new ArgumentNullException(nameof(random));
}
var seed = random.Next();
int seed = random.Next();
var seededRandom = new Random(seed);
var angle = seededRandom.NextSingle(0, 360).DegreesToRadians();

View File

@ -92,8 +92,8 @@ namespace X10D
if (!interfaceType.IsInterface)
{
var exceptionMessage = ExceptionMessages.TypeIsNotInterface;
var formattedMessage = string.Format(CultureInfo.CurrentCulture, exceptionMessage, interfaceType);
string? exceptionMessage = ExceptionMessages.TypeIsNotInterface;
string? formattedMessage = string.Format(CultureInfo.CurrentCulture, exceptionMessage, interfaceType);
throw new ArgumentException(formattedMessage, nameof(interfaceType));
}
@ -139,16 +139,16 @@ namespace X10D
if (!value.IsClass)
{
var exceptionMessage = ExceptionMessages.TypeIsNotClass;
var formattedMessage = string.Format(CultureInfo.CurrentCulture, exceptionMessage, value);
string? exceptionMessage = ExceptionMessages.TypeIsNotClass;
string? formattedMessage = string.Format(CultureInfo.CurrentCulture, exceptionMessage, value);
throw new ArgumentException(formattedMessage, nameof(value));
}
if (!type.IsClass)
{
var exceptionMessage = ExceptionMessages.TypeIsNotClass;
var formattedMessage = string.Format(CultureInfo.CurrentCulture, exceptionMessage, type);
string? exceptionMessage = ExceptionMessages.TypeIsNotClass;
string? formattedMessage = string.Format(CultureInfo.CurrentCulture, exceptionMessage, type);
throw new ArgumentException(formattedMessage, nameof(type));
}

View File

@ -13,7 +13,7 @@
private static void SwapIfNeeded(ref byte[] buffer, Endianness endianness)
{
var swapNeeded = BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian);
bool swapNeeded = BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian);
if (swapNeeded)
{
Array.Reverse(buffer);
@ -24,14 +24,14 @@
{
var clone = (byte[])value.Clone();
SwapIfNeeded(ref clone, endianness);
var preWritePosition = stream.Position;
long preWritePosition = stream.Position;
stream.Write(clone, 0, clone.Length);
return (int)(stream.Position - preWritePosition);
}
private static int WriteInternal(this Stream stream, Span<byte> value)
{
var preWritePosition = stream.Position;
long preWritePosition = stream.Position;
stream.Write(value);
return (int)(stream.Position - preWritePosition);
}

View File

@ -797,10 +797,10 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness));
}
var bits = decimal.GetBits(value);
var preWritePosition = stream.Position;
int[]? bits = decimal.GetBits(value);
long preWritePosition = stream.Position;
foreach (var section in bits)
foreach (int section in bits)
{
stream.Write(section, endianness);
}

View File

@ -331,7 +331,7 @@ namespace X10D
unsafe
{
var array = stackalloc char[value.Length];
char* array = stackalloc char[value.Length];
for (var index = 0; index < value.Length; index++)
{
@ -410,7 +410,7 @@ namespace X10D
throw new ArgumentNullException(nameof(input));
}
return TimeSpanParser.TryParse(input, out var result)
return TimeSpanParser.TryParse(input, out TimeSpan result)
? result
: default;
}

View File

@ -1,4 +1,4 @@
using System.Globalization;
using System.Globalization;
using System.Text.RegularExpressions;
namespace X10D
@ -33,7 +33,7 @@ namespace X10D
{
result = default;
var match = Regex.Match(input);
Match? match = Regex.Match(input);
if (!match.Success)
{
@ -48,42 +48,42 @@ namespace X10D
&& double.TryParse(match.Groups[group].Value, NumberStyles.Number, provider, out parsedResult);
}
if (!TryParseAt(1, out var years))
if (!TryParseAt(1, out double years))
{
return false;
}
if (!TryParseAt(2, out var months))
if (!TryParseAt(2, out double months))
{
return false;
}
if (!TryParseAt(3, out var weeks))
if (!TryParseAt(3, out double weeks))
{
return false;
}
if (!TryParseAt(4, out var days))
if (!TryParseAt(4, out double days))
{
return false;
}
if (!TryParseAt(5, out var hours))
if (!TryParseAt(5, out double hours))
{
return false;
}
if (!TryParseAt(6, out var minutes))
if (!TryParseAt(6, out double minutes))
{
return false;
}
if (!TryParseAt(7, out var seconds))
if (!TryParseAt(7, out double seconds))
{
return false;
}
if (!TryParseAt(8, out var milliseconds))
if (!TryParseAt(8, out double milliseconds))
{
return false;
}