chore: Use var everywhere (#2294)
This commit is contained in:
parent
0b34cc4417
commit
ebaf104935
267 changed files with 873 additions and 873 deletions
|
|
@ -45,9 +45,9 @@ public static class ActivatorExtensions
|
|||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < ctors.Length; i++)
|
||||
for (var i = 0; i < ctors.Length; i++)
|
||||
{
|
||||
ConstructorInfo info = ctors[i];
|
||||
var info = ctors[i];
|
||||
|
||||
if (predicate?.Invoke(info) == false)
|
||||
{
|
||||
|
|
@ -62,12 +62,12 @@ public static class ActivatorExtensions
|
|||
continue;
|
||||
}
|
||||
|
||||
bool validated = true;
|
||||
var validated = true;
|
||||
|
||||
// Check that all args match params
|
||||
for (var j = 0; j < parameters.Length; j++)
|
||||
{
|
||||
ParameterInfo param = parameters[j];
|
||||
var param = parameters[j];
|
||||
|
||||
// All extra parameters must be optional
|
||||
if (j >= args.Length)
|
||||
|
|
@ -124,7 +124,7 @@ public static class ActivatorExtensions
|
|||
var argLength = args?.Length ?? 0;
|
||||
|
||||
var types = argLength > 0 ? new Type[argLength] : [];
|
||||
for (int i = 0; i < types.Length; i++)
|
||||
for (var i = 0; i < types.Length; i++)
|
||||
{
|
||||
types[i] = args![i]?.GetType();
|
||||
}
|
||||
|
|
@ -148,7 +148,7 @@ public static class ActivatorExtensions
|
|||
else
|
||||
{
|
||||
paramArgs = new object[paramCount];
|
||||
for (int i = 0; i < paramCount; i++)
|
||||
for (var i = 0; i < paramCount; i++)
|
||||
{
|
||||
paramArgs[i] = i < argLength ? args![i] : Type.Missing;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,10 +76,10 @@ public static class HashUtility
|
|||
fixed (char* src = &str.GetPinnableReference())
|
||||
{
|
||||
uint hash1 = (5381 << 16) + 5381;
|
||||
uint hash2 = hash1;
|
||||
var hash2 = hash1;
|
||||
|
||||
uint* ptr = (uint*)src;
|
||||
int length = str.Length;
|
||||
var ptr = (uint*)src;
|
||||
var length = str.Length;
|
||||
|
||||
while (length > 2)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -167,14 +167,14 @@ public static class Html
|
|||
return string.Empty;
|
||||
}
|
||||
|
||||
int indexOfAny = input.IndexOfAny(_htmlSearchValues);
|
||||
var indexOfAny = input.IndexOfAny(_htmlSearchValues);
|
||||
if (indexOfAny < 0)
|
||||
{
|
||||
return input.ToString();
|
||||
}
|
||||
|
||||
using var builder = ValueStringBuilder.Create(input.Length * 2);
|
||||
int lastIndex = 0;
|
||||
var lastIndex = 0;
|
||||
|
||||
while (indexOfAny >= 0)
|
||||
{
|
||||
|
|
@ -183,7 +183,7 @@ public static class Html
|
|||
builder.Append(input[lastIndex..indexOfAny]);
|
||||
}
|
||||
|
||||
char c = input[indexOfAny];
|
||||
var c = input[indexOfAny];
|
||||
var replacement = c switch
|
||||
{
|
||||
'&' => "&",
|
||||
|
|
|
|||
|
|
@ -75,17 +75,17 @@ public static class PathUtility
|
|||
|
||||
Directory.CreateDirectory(destDir);
|
||||
|
||||
foreach (FileInfo file in dir.GetFiles())
|
||||
foreach (var file in dir.GetFiles())
|
||||
{
|
||||
string targetFilePath = Path.Combine(destDir, file.Name);
|
||||
var targetFilePath = Path.Combine(destDir, file.Name);
|
||||
file.CopyTo(targetFilePath, true);
|
||||
}
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
foreach (DirectoryInfo subdir in dir.GetDirectories())
|
||||
foreach (var subdir in dir.GetDirectories())
|
||||
{
|
||||
string destSubDir = Path.Combine(destDir, subdir.Name);
|
||||
var destSubDir = Path.Combine(destDir, subdir.Name);
|
||||
CopyDirectoryContents(subdir.FullName, destSubDir);
|
||||
}
|
||||
}
|
||||
|
|
@ -102,16 +102,16 @@ public static class PathUtility
|
|||
|
||||
Directory.CreateDirectory(destDir);
|
||||
|
||||
foreach (FileInfo file in dir.GetFiles())
|
||||
foreach (var file in dir.GetFiles())
|
||||
{
|
||||
file.MoveTo(Path.Combine(destDir, file.Name));
|
||||
}
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
foreach (DirectoryInfo subdir in dir.GetDirectories())
|
||||
foreach (var subdir in dir.GetDirectories())
|
||||
{
|
||||
string destSubDir = Path.Combine(destDir, subdir.Name);
|
||||
var destSubDir = Path.Combine(destDir, subdir.Name);
|
||||
MoveDirectoryContents(subdir.FullName, destSubDir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,16 +93,16 @@ public static partial class Utility
|
|||
|
||||
if (prefixLength < 64)
|
||||
{
|
||||
int bitsToFlip = 64 - prefixLength;
|
||||
ulong highMask = isMax ? ~0UL >> bitsToFlip : ~0UL << (bitsToFlip + 1);
|
||||
var bitsToFlip = 64 - prefixLength;
|
||||
var highMask = isMax ? ~0UL >> bitsToFlip : ~0UL << (bitsToFlip + 1);
|
||||
|
||||
high = isMax ? high | highMask : high & highMask;
|
||||
low = isMax ? ~0UL : 0UL;
|
||||
}
|
||||
else
|
||||
{
|
||||
int bitsToFlip = 128 - prefixLength;
|
||||
ulong lowMask = isMax ? ~0UL >> (64 - bitsToFlip) : ~0UL << bitsToFlip;
|
||||
var bitsToFlip = 128 - prefixLength;
|
||||
var lowMask = isMax ? ~0UL >> (64 - bitsToFlip) : ~0UL << bitsToFlip;
|
||||
|
||||
low = isMax ? low | lowMask : low & lowMask;
|
||||
}
|
||||
|
|
@ -125,8 +125,8 @@ public static partial class Utility
|
|||
return 0;
|
||||
}
|
||||
|
||||
ulong high = BinaryPrimitives.ReadUInt64BigEndian(bytes[..8]);
|
||||
ulong low = BinaryPrimitives.ReadUInt64BigEndian(bytes.Slice(8, 8));
|
||||
var high = BinaryPrimitives.ReadUInt64BigEndian(bytes[..8]);
|
||||
var low = BinaryPrimitives.ReadUInt64BigEndian(bytes.Slice(8, 8));
|
||||
|
||||
return new UInt128(high, low);
|
||||
}
|
||||
|
|
@ -150,8 +150,8 @@ public static partial class Utility
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static UInt128 CreateCidrAddress(ReadOnlySpan<byte> bytes, int prefixLength, bool isMax)
|
||||
{
|
||||
ulong high = BinaryPrimitives.ReadUInt64BigEndian(bytes[..8]);
|
||||
ulong low = BinaryPrimitives.ReadUInt64BigEndian(bytes.Slice(8, 8));
|
||||
var high = BinaryPrimitives.ReadUInt64BigEndian(bytes[..8]);
|
||||
var low = BinaryPrimitives.ReadUInt64BigEndian(bytes.Slice(8, 8));
|
||||
|
||||
if (prefixLength < 128)
|
||||
{
|
||||
|
|
@ -588,7 +588,7 @@ public static partial class Utility
|
|||
while (amount > 0)
|
||||
{
|
||||
// Range is 2^amount exclusively, maximum of 62 bits can be used
|
||||
ulong num = amount >= 62
|
||||
var num = amount >= 62
|
||||
? (ulong)BuiltInRng.NextLong()
|
||||
: (ulong)BuiltInRng.Next(1L << amount);
|
||||
|
||||
|
|
@ -612,7 +612,7 @@ public static partial class Utility
|
|||
while (amount > 0)
|
||||
{
|
||||
// Range is 2^amount exclusively, maximum of 62 bits can be used
|
||||
ulong num = amount >= 62
|
||||
var num = amount >= 62
|
||||
? (ulong)BuiltInRng.NextLong()
|
||||
: (ulong)BuiltInRng.Next(1L << amount);
|
||||
|
||||
|
|
@ -1059,7 +1059,7 @@ public static partial class Utility
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Tidy<T>(this List<T> list) where T : ISerializable
|
||||
{
|
||||
for (int i = list.Count - 1; i >= 0; i--)
|
||||
for (var i = list.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var entry = list[i];
|
||||
if (entry?.Deleted != false)
|
||||
|
|
@ -1127,7 +1127,7 @@ public static partial class Utility
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int Abs(this int value)
|
||||
{
|
||||
int mask = value >> 31;
|
||||
var mask = value >> 31;
|
||||
return (value + mask) ^ mask;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue