Enable implicit usings

This commit is contained in:
Oliver Booth 2022-02-14 12:00:37 +00:00
parent 14a0f2fdd4
commit 920750a207
21 changed files with 26 additions and 145 deletions

View File

@ -5,6 +5,7 @@
<LangVersion>10.0</LangVersion> <LangVersion>10.0</LangVersion>
<EnablePreviewFeatures>true</EnablePreviewFeatures> <EnablePreviewFeatures>true</EnablePreviewFeatures>
<GenerateRequiresPreviewFeaturesAttribute>false</GenerateRequiresPreviewFeaturesAttribute> <GenerateRequiresPreviewFeaturesAttribute>false</GenerateRequiresPreviewFeaturesAttribute>
<ImplicitUsings>true</ImplicitUsings>
<Authors>Oliver Booth</Authors> <Authors>Oliver Booth</Authors>
<NeutralLanguage>en</NeutralLanguage> <NeutralLanguage>en</NeutralLanguage>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>

View File

@ -1,6 +1,4 @@
using System; namespace X10D
namespace X10D
{ {
/// <summary> /// <summary>
/// Extension methods for <see cref="bool" />. /// Extension methods for <see cref="bool" />.

View File

@ -1,6 +1,4 @@
using System; namespace X10D
namespace X10D
{ {
/// <summary> /// <summary>
/// Extension methods for <see cref="char" />. /// Extension methods for <see cref="char" />.

View File

@ -1,8 +1,4 @@
using System; namespace X10D
using System.Collections.Generic;
using System.Linq;
namespace X10D
{ {
/// <summary> /// <summary>
/// Extension methods for <see cref="ICollection{T}" /> and <see cref="IReadOnlyCollection{T}" />. /// Extension methods for <see cref="ICollection{T}" /> and <see cref="IReadOnlyCollection{T}" />.

View File

@ -1,4 +1,3 @@
using System;
using System.Globalization; using System.Globalization;
namespace X10D namespace X10D

View File

@ -1,5 +1,3 @@
using System;
using System.Collections.Generic;
using System.Web; using System.Web;
namespace X10D namespace X10D

View File

@ -1,5 +1,3 @@
using System;
namespace X10D namespace X10D
{ {
/// <summary> /// <summary>

View File

@ -1,4 +1,3 @@
using System;
using System.Net; using System.Net;
namespace X10D namespace X10D

View File

@ -1,4 +1,3 @@
using System;
using System.Net; using System.Net;
namespace X10D namespace X10D

View File

@ -1,4 +1,3 @@
using System;
using System.Net; using System.Net;
namespace X10D namespace X10D

View File

@ -1,7 +1,4 @@
using System; namespace X10D
using System.Collections.Generic;
namespace X10D
{ {
/// <summary> /// <summary>
/// Extension methods for <see cref="IList{T}" /> and <see cref="IReadOnlyList{T}" />. /// Extension methods for <see cref="IList{T}" /> and <see cref="IReadOnlyList{T}" />.

View File

@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Text; using System.Text;
namespace X10D namespace X10D

View File

@ -1,5 +1,3 @@
#if NET5_0
using System;
using System.Numerics; using System.Numerics;
namespace X10D.SystemNumerics namespace X10D.SystemNumerics
@ -116,5 +114,3 @@ namespace X10D.SystemNumerics
} }
} }
} }
#endif

View File

@ -1,5 +1,4 @@
using System; using System.Globalization;
using System.Globalization;
using System.Reflection; using System.Reflection;
namespace X10D namespace X10D

View File

@ -1,5 +1,4 @@
using System; using System.Globalization;
using System.Globalization;
using System.Reflection; using System.Reflection;
namespace X10D namespace X10D

View File

@ -1,5 +1,3 @@
using System;
namespace X10D namespace X10D
{ {
/// <summary> /// <summary>

View File

@ -1,7 +1,4 @@
using System; namespace X10D
using System.IO;
namespace X10D
{ {
public static partial class StreamExtensions public static partial class StreamExtensions
{ {
@ -32,13 +29,11 @@ namespace X10D
return (int)(stream.Position - preWritePosition); return (int)(stream.Position - preWritePosition);
} }
#if NET5_0
private static int WriteInternal(this Stream stream, Span<byte> value) private static int WriteInternal(this Stream stream, Span<byte> value)
{ {
var preWritePosition = stream.Position; var preWritePosition = stream.Position;
stream.Write(value); stream.Write(value);
return (int)(stream.Position - preWritePosition); return (int)(stream.Position - preWritePosition);
} }
#endif
} }
} }

View File

@ -1,10 +1,6 @@
using System; using System.Reflection;
using System.IO;
using System.Reflection;
using System.Security.Cryptography; using System.Security.Cryptography;
#if NET5_0
using System.Buffers.Binary; using System.Buffers.Binary;
#endif
namespace X10D namespace X10D
{ {
@ -135,17 +131,13 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#if NET5_0
Span<byte> buffer = stackalloc byte[sizeof(int)]; Span<byte> buffer = stackalloc byte[sizeof(int)];
stream.Read(buffer); stream.Read(buffer);
return endianness == Endianness.LittleEndian return endianness == Endianness.LittleEndian
? BinaryPrimitives.ReadDoubleLittleEndian(buffer) ? BinaryPrimitives.ReadDoubleLittleEndian(buffer)
: BinaryPrimitives.ReadDoubleBigEndian(buffer); : BinaryPrimitives.ReadDoubleBigEndian(buffer);
#else
var value = ReadInternal<double>(stream, endianness);
return BitConverter.ToDouble(value, 0);
#endif
} }
/// <summary> /// <summary>
@ -178,17 +170,13 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#if NET5_0
Span<byte> buffer = stackalloc byte[sizeof(int)]; Span<byte> buffer = stackalloc byte[sizeof(int)];
stream.Read(buffer); stream.Read(buffer);
return endianness == Endianness.LittleEndian return endianness == Endianness.LittleEndian
? BinaryPrimitives.ReadInt16LittleEndian(buffer) ? BinaryPrimitives.ReadInt16LittleEndian(buffer)
: BinaryPrimitives.ReadInt16BigEndian(buffer); : BinaryPrimitives.ReadInt16BigEndian(buffer);
#else
var value = ReadInternal<short>(stream, endianness);
return BitConverter.ToInt16(value, 0);
#endif
} }
/// <summary> /// <summary>
@ -221,17 +209,13 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#if NET5_0
Span<byte> buffer = stackalloc byte[sizeof(int)]; Span<byte> buffer = stackalloc byte[sizeof(int)];
stream.Read(buffer); stream.Read(buffer);
return endianness == Endianness.LittleEndian return endianness == Endianness.LittleEndian
? BinaryPrimitives.ReadInt32LittleEndian(buffer) ? BinaryPrimitives.ReadInt32LittleEndian(buffer)
: BinaryPrimitives.ReadInt32BigEndian(buffer); : BinaryPrimitives.ReadInt32BigEndian(buffer);
#else
var value = ReadInternal<int>(stream, endianness);
return BitConverter.ToInt32(value, 0);
#endif
} }
/// <summary> /// <summary>
@ -264,17 +248,13 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#if NET5_0
Span<byte> buffer = stackalloc byte[sizeof(int)]; Span<byte> buffer = stackalloc byte[sizeof(int)];
stream.Read(buffer); stream.Read(buffer);
return endianness == Endianness.LittleEndian return endianness == Endianness.LittleEndian
? BinaryPrimitives.ReadInt64LittleEndian(buffer) ? BinaryPrimitives.ReadInt64LittleEndian(buffer)
: BinaryPrimitives.ReadInt64BigEndian(buffer); : BinaryPrimitives.ReadInt64BigEndian(buffer);
#else
var value = ReadInternal<long>(stream, endianness);
return BitConverter.ToInt64(value, 0);
#endif
} }
/// <summary> /// <summary>
@ -307,17 +287,13 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#if NET5_0
Span<byte> buffer = stackalloc byte[sizeof(int)]; Span<byte> buffer = stackalloc byte[sizeof(int)];
stream.Read(buffer); stream.Read(buffer);
return endianness == Endianness.LittleEndian return endianness == Endianness.LittleEndian
? BinaryPrimitives.ReadSingleLittleEndian(buffer) ? BinaryPrimitives.ReadSingleLittleEndian(buffer)
: BinaryPrimitives.ReadSingleBigEndian(buffer); : BinaryPrimitives.ReadSingleBigEndian(buffer);
#else
var value = ReadInternal<float>(stream, endianness);
return BitConverter.ToSingle(value, 0);
#endif
} }
/// <summary> /// <summary>
@ -352,17 +328,13 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#if NET5_0
Span<byte> buffer = stackalloc byte[sizeof(int)]; Span<byte> buffer = stackalloc byte[sizeof(int)];
stream.Read(buffer); stream.Read(buffer);
return endianness == Endianness.LittleEndian return endianness == Endianness.LittleEndian
? BinaryPrimitives.ReadUInt16LittleEndian(buffer) ? BinaryPrimitives.ReadUInt16LittleEndian(buffer)
: BinaryPrimitives.ReadUInt16BigEndian(buffer); : BinaryPrimitives.ReadUInt16BigEndian(buffer);
#else
var value = ReadInternal<ushort>(stream, endianness);
return BitConverter.ToUInt16(value, 0);
#endif
} }
/// <summary> /// <summary>
@ -397,17 +369,13 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#if NET5_0
Span<byte> buffer = stackalloc byte[sizeof(int)]; Span<byte> buffer = stackalloc byte[sizeof(int)];
stream.Read(buffer); stream.Read(buffer);
return endianness == Endianness.LittleEndian return endianness == Endianness.LittleEndian
? BinaryPrimitives.ReadUInt32LittleEndian(buffer) ? BinaryPrimitives.ReadUInt32LittleEndian(buffer)
: BinaryPrimitives.ReadUInt32BigEndian(buffer); : BinaryPrimitives.ReadUInt32BigEndian(buffer);
#else
var value = ReadInternal<uint>(stream, endianness);
return BitConverter.ToUInt32(value, 0);
#endif
} }
/// <summary> /// <summary>
@ -442,17 +410,13 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#if NET5_0
Span<byte> buffer = stackalloc byte[sizeof(int)]; Span<byte> buffer = stackalloc byte[sizeof(int)];
stream.Read(buffer); stream.Read(buffer);
return endianness == Endianness.LittleEndian return endianness == Endianness.LittleEndian
? BinaryPrimitives.ReadUInt64LittleEndian(buffer) ? BinaryPrimitives.ReadUInt64LittleEndian(buffer)
: BinaryPrimitives.ReadUInt64BigEndian(buffer); : BinaryPrimitives.ReadUInt64BigEndian(buffer);
#else
var value = ReadInternal<ulong>(stream, endianness);
return BitConverter.ToUInt64(value, 0);
#endif
} }
/// <summary> /// <summary>
@ -487,7 +451,7 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#if NET5_0
Span<byte> buffer = stackalloc byte[sizeof(short)]; Span<byte> buffer = stackalloc byte[sizeof(short)];
if (endianness == Endianness.LittleEndian) if (endianness == Endianness.LittleEndian)
@ -500,10 +464,6 @@ namespace X10D
} }
return stream.WriteInternal(buffer); return stream.WriteInternal(buffer);
#else
var buffer = BitConverter.GetBytes(value);
return stream.WriteInternal(buffer, endianness);
#endif
} }
/// <summary> /// <summary>
@ -538,7 +498,7 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#if NET5_0
Span<byte> buffer = stackalloc byte[sizeof(int)]; Span<byte> buffer = stackalloc byte[sizeof(int)];
if (endianness == Endianness.LittleEndian) if (endianness == Endianness.LittleEndian)
@ -551,10 +511,6 @@ namespace X10D
} }
return stream.WriteInternal(buffer); return stream.WriteInternal(buffer);
#else
var buffer = BitConverter.GetBytes(value);
return stream.WriteInternal(buffer, endianness);
#endif
} }
/// <summary> /// <summary>
@ -589,7 +545,7 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#if NET5_0
Span<byte> buffer = stackalloc byte[sizeof(long)]; Span<byte> buffer = stackalloc byte[sizeof(long)];
if (endianness == Endianness.LittleEndian) if (endianness == Endianness.LittleEndian)
@ -602,10 +558,6 @@ namespace X10D
} }
return stream.WriteInternal(buffer); return stream.WriteInternal(buffer);
#else
var buffer = BitConverter.GetBytes(value);
return stream.WriteInternal(buffer, endianness);
#endif
} }
/// <summary> /// <summary>
@ -642,7 +594,7 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#if NET5_0
Span<byte> buffer = stackalloc byte[sizeof(ushort)]; Span<byte> buffer = stackalloc byte[sizeof(ushort)];
if (endianness == Endianness.LittleEndian) if (endianness == Endianness.LittleEndian)
@ -655,10 +607,6 @@ namespace X10D
} }
return stream.WriteInternal(buffer); return stream.WriteInternal(buffer);
#else
var buffer = BitConverter.GetBytes(value);
return stream.WriteInternal(buffer, endianness);
#endif
} }
/// <summary> /// <summary>
@ -695,7 +643,7 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#if NET5_0
Span<byte> buffer = stackalloc byte[sizeof(uint)]; Span<byte> buffer = stackalloc byte[sizeof(uint)];
if (endianness == Endianness.LittleEndian) if (endianness == Endianness.LittleEndian)
@ -708,10 +656,6 @@ namespace X10D
} }
return stream.WriteInternal(buffer); return stream.WriteInternal(buffer);
#else
var buffer = BitConverter.GetBytes(value);
return stream.WriteInternal(buffer, endianness);
#endif
} }
/// <summary> /// <summary>
@ -748,7 +692,7 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#if NET5_0
Span<byte> buffer = stackalloc byte[sizeof(ulong)]; Span<byte> buffer = stackalloc byte[sizeof(ulong)];
if (endianness == Endianness.LittleEndian) if (endianness == Endianness.LittleEndian)
@ -761,10 +705,6 @@ namespace X10D
} }
return stream.WriteInternal(buffer); return stream.WriteInternal(buffer);
#else
var buffer = BitConverter.GetBytes(value);
return stream.WriteInternal(buffer, endianness);
#endif
} }
/// <summary> /// <summary>
@ -787,7 +727,7 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#if NET5_0
Span<byte> buffer = stackalloc byte[sizeof(float)]; Span<byte> buffer = stackalloc byte[sizeof(float)];
if (endianness == Endianness.LittleEndian) if (endianness == Endianness.LittleEndian)
@ -800,10 +740,6 @@ namespace X10D
} }
return stream.WriteInternal(buffer); return stream.WriteInternal(buffer);
#else
var buffer = BitConverter.GetBytes(value);
return stream.WriteInternal(buffer, endianness);
#endif
} }
/// <summary> /// <summary>
@ -826,7 +762,7 @@ namespace X10D
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#if NET5_0
Span<byte> buffer = stackalloc byte[sizeof(double)]; Span<byte> buffer = stackalloc byte[sizeof(double)];
if (endianness == Endianness.LittleEndian) if (endianness == Endianness.LittleEndian)
@ -839,10 +775,6 @@ namespace X10D
} }
return stream.WriteInternal(buffer); return stream.WriteInternal(buffer);
#else
var buffer = BitConverter.GetBytes(value);
return stream.WriteInternal(buffer, endianness);
#endif
} }
/// <summary> /// <summary>

View File

@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
namespace X10D namespace X10D
@ -136,16 +133,7 @@ namespace X10D
throw new ArgumentException(Resource.EnumParseEmptyStringException, nameof(value)); throw new ArgumentException(Resource.EnumParseEmptyStringException, nameof(value));
} }
#if NET5_0_OR_GREATER
return Enum.Parse<T>(value, ignoreCase); return Enum.Parse<T>(value, ignoreCase);
#else
if (typeof(T) is not { IsEnum: true } type)
{
throw new ArgumentException(Resource.EnumParseNotEnumException);
}
return (T)Enum.Parse(type, value, ignoreCase);
#endif
} }
/// <summary> /// <summary>

View File

@ -1,4 +1,3 @@
using System;
using System.Globalization; using System.Globalization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;

View File

@ -1,8 +1,4 @@
using System; namespace X10D
using System.Threading;
using System.Threading.Tasks;
namespace X10D
{ {
/// <summary> /// <summary>
/// Extension methods for <see cref="WaitHandle" />. /// Extension methods for <see cref="WaitHandle" />.