fix(build): Attempt to fix possible nullable warnings as errors with releases (#418)

This commit is contained in:
Kamron Batman 2021-01-18 11:52:31 -08:00 committed by GitHub
parent 08f05afd01
commit 87764ca968
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 23 additions and 11 deletions

View file

@ -29,7 +29,7 @@ namespace System.Buffers
public ref struct SpanWriter
{
private readonly bool _resize;
private byte[]? _arrayToReturnToPool;
private byte[] _arrayToReturnToPool;
private Span<byte> _buffer;
private int _position;
@ -81,7 +81,7 @@ namespace System.Buffers
_buffer.SliceToLength(BytesWritten).CopyTo(poolArray);
byte[]? toReturn = _arrayToReturnToPool;
byte[] toReturn = _arrayToReturnToPool;
_buffer = _arrayToReturnToPool = poolArray;
if (toReturn != null)
{

View file

@ -11,7 +11,7 @@ namespace Server.Buffers
{
public ref struct ValueStringBuilder
{
private char[]? _arrayToReturnToPool;
private char[] _arrayToReturnToPool;
private Span<char> _chars;
// If this ctor is used, you cannot pass in stackalloc ROS for append/replace.
@ -124,7 +124,7 @@ namespace Server.Buffers
Length += count;
}
public void Insert(int index, string? s)
public void Insert(int index, string s)
{
if (s == null)
{
@ -160,7 +160,7 @@ namespace Server.Buffers
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Append(string? s)
public void Append(string s)
{
if (s == null)
{
@ -180,7 +180,7 @@ namespace Server.Buffers
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AppendLine(string? s)
public void AppendLine(string s)
{
if (s == null)
{
@ -275,6 +275,7 @@ namespace Server.Buffers
Append(c);
}
#nullable enable
/// <summary>
/// Resize the internal buffer either by doubling current buffer size or
/// by adding <paramref name="additionalCapacityBeyondPos"/> to
@ -290,7 +291,7 @@ namespace Server.Buffers
_chars.SliceToLength(Length).CopyTo(poolArray);
char[]? toReturn = _arrayToReturnToPool;
char[] toReturn = _arrayToReturnToPool;
_chars = _arrayToReturnToPool = poolArray;
if (toReturn != null)
{
@ -301,13 +302,14 @@ namespace Server.Buffers
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose()
{
char[]? toReturn = _arrayToReturnToPool;
char[] toReturn = _arrayToReturnToPool;
this = default; // for safety, to avoid using pooled array if this instance is erroneously appended to again
if (toReturn != null)
{
ArrayPool<char>.Shared.Return(toReturn);
}
}
#nullable disable
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ReplaceAny(ReadOnlySpan<char> oldChars, ReadOnlySpan<char> newChars, int startIndex, int count)

View file

@ -492,6 +492,7 @@ namespace Server.Collections
return index;
}
#nullable enable
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private int TryInsert(int? index, TValue value)
{
@ -525,6 +526,7 @@ namespace Server.Collections
++_version;
return actualIndex;
}
#nullable disable
// Returns the index of the next entry in the bucket
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -2411,6 +2411,7 @@ namespace Server
m_PropertyList = null;
}
#nullable enable
public void InvalidateProperties()
{
if (!ObjectPropertyList.Enabled)
@ -2445,6 +2446,7 @@ namespace Server
ClearProperties();
}
}
#nullable disable
public virtual int GetPacketFlags()
{

View file

@ -7398,6 +7398,7 @@ namespace Server
m_PropertyList = null;
}
#nullable enable
public void InvalidateProperties()
{
if (!ObjectPropertyList.Enabled)
@ -7432,6 +7433,7 @@ namespace Server
ClearProperties();
}
}
#nullable disable
public virtual void SetLocation(Point3D newLocation, bool isTeleport)
{

View file

@ -27,7 +27,7 @@ namespace Server.Network
private bool _finished;
private int _count;
private byte[]? _arrayToReturnToPool;
private byte[] _arrayToReturnToPool;
private Span<byte> _bytes;
public PacketContainerBuilder(Span<byte> initialBuffer)
@ -93,7 +93,7 @@ namespace Server.Network
_bytes.SliceToLength(Length).CopyTo(poolArray);
byte[]? toReturn = _arrayToReturnToPool;
byte[] toReturn = _arrayToReturnToPool;
_bytes = _arrayToReturnToPool = poolArray;
if (toReturn != null)
{
@ -104,7 +104,7 @@ namespace Server.Network
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose()
{
byte[]? toReturn = _arrayToReturnToPool;
byte[] toReturn = _arrayToReturnToPool;
this = default; // for safety, to avoid using pooled array if this instance is erroneously appended to again
if (toReturn != null)
{

View file

@ -25,7 +25,9 @@ namespace Server.Commands
[JsonPropertyName("gfx")] public int ItemID { get; set; }
#nullable enable
[JsonPropertyName("hue")] public int? Hue { get; set; }
#nullable disable
public CAGCategory Parent { get; set; }

View file

@ -72,6 +72,7 @@ namespace Server.Commands
JsonConfig.Serialize(fileName, list);
}
#nullable enable
public static void RecurseExport(List<CAGJson> list, CategoryEntry ce, string category)
{
category = string.IsNullOrWhiteSpace(category) ? ce.Title : $"{category}{ce.Title}";
@ -153,6 +154,7 @@ namespace Server.Commands
RecurseExport(list, subCat, category);
}
}
#nullable disable
public static void Load()
{