From 87764ca9683cfba413e14b62b593ee34fd181a92 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Mon, 18 Jan 2021 11:52:31 -0800 Subject: [PATCH] fix(build): Attempt to fix possible nullable warnings as errors with releases (#418) --- Projects/Server/Buffers/SpanWriter.cs | 4 ++-- Projects/Server/Buffers/ValueStringBuilder.cs | 14 ++++++++------ Projects/Server/Collections/OrderedHashSet.cs | 2 ++ Projects/Server/Items/Item.cs | 2 ++ Projects/Server/Mobiles/Mobile.cs | 2 ++ .../Network/Packets/PacketContainerBuilder.cs | 6 +++--- .../Commands/Object Creation/CAGObject.cs | 2 ++ .../Commands/Object Creation/Categorization.cs | 2 ++ 8 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Projects/Server/Buffers/SpanWriter.cs b/Projects/Server/Buffers/SpanWriter.cs index 67f69f1c7..21460a427 100644 --- a/Projects/Server/Buffers/SpanWriter.cs +++ b/Projects/Server/Buffers/SpanWriter.cs @@ -29,7 +29,7 @@ namespace System.Buffers public ref struct SpanWriter { private readonly bool _resize; - private byte[]? _arrayToReturnToPool; + private byte[] _arrayToReturnToPool; private Span _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) { diff --git a/Projects/Server/Buffers/ValueStringBuilder.cs b/Projects/Server/Buffers/ValueStringBuilder.cs index 3f5820f85..45fc9f1ec 100644 --- a/Projects/Server/Buffers/ValueStringBuilder.cs +++ b/Projects/Server/Buffers/ValueStringBuilder.cs @@ -11,7 +11,7 @@ namespace Server.Buffers { public ref struct ValueStringBuilder { - private char[]? _arrayToReturnToPool; + private char[] _arrayToReturnToPool; private Span _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 /// /// Resize the internal buffer either by doubling current buffer size or /// by adding 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.Shared.Return(toReturn); } } +#nullable disable [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ReplaceAny(ReadOnlySpan oldChars, ReadOnlySpan newChars, int startIndex, int count) diff --git a/Projects/Server/Collections/OrderedHashSet.cs b/Projects/Server/Collections/OrderedHashSet.cs index 29bc6efbf..d738b8035 100644 --- a/Projects/Server/Collections/OrderedHashSet.cs +++ b/Projects/Server/Collections/OrderedHashSet.cs @@ -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)] diff --git a/Projects/Server/Items/Item.cs b/Projects/Server/Items/Item.cs index af3311335..6abafb23d 100644 --- a/Projects/Server/Items/Item.cs +++ b/Projects/Server/Items/Item.cs @@ -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() { diff --git a/Projects/Server/Mobiles/Mobile.cs b/Projects/Server/Mobiles/Mobile.cs index 57bc4b552..3bf10a618 100644 --- a/Projects/Server/Mobiles/Mobile.cs +++ b/Projects/Server/Mobiles/Mobile.cs @@ -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) { diff --git a/Projects/Server/Network/Packets/PacketContainerBuilder.cs b/Projects/Server/Network/Packets/PacketContainerBuilder.cs index 5d13cb231..7fb49a6a7 100644 --- a/Projects/Server/Network/Packets/PacketContainerBuilder.cs +++ b/Projects/Server/Network/Packets/PacketContainerBuilder.cs @@ -27,7 +27,7 @@ namespace Server.Network private bool _finished; private int _count; - private byte[]? _arrayToReturnToPool; + private byte[] _arrayToReturnToPool; private Span _bytes; public PacketContainerBuilder(Span 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) { diff --git a/Projects/UOContent/Commands/Object Creation/CAGObject.cs b/Projects/UOContent/Commands/Object Creation/CAGObject.cs index f65f089b5..6d122e65c 100644 --- a/Projects/UOContent/Commands/Object Creation/CAGObject.cs +++ b/Projects/UOContent/Commands/Object Creation/CAGObject.cs @@ -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; } diff --git a/Projects/UOContent/Commands/Object Creation/Categorization.cs b/Projects/UOContent/Commands/Object Creation/Categorization.cs index c4e60ac6d..189398da2 100644 --- a/Projects/UOContent/Commands/Object Creation/Categorization.cs +++ b/Projects/UOContent/Commands/Object Creation/Categorization.cs @@ -72,6 +72,7 @@ namespace Server.Commands JsonConfig.Serialize(fileName, list); } +#nullable enable public static void RecurseExport(List 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() {