summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ModLoading/AssemblyParseResult.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-13 21:07:43 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-13 21:07:43 -0400
commit4adf8611131a5d86b15f017a42a0366837d14528 (patch)
tree879ba8dfc546382c3795e3d13a623b0e17f96469 /src/SMAPI/Framework/ModLoading/AssemblyParseResult.cs
parent5b24fff4771dd11c627ae20c827599fe37fa89ad (diff)
downloadSMAPI-4adf8611131a5d86b15f017a42a0366837d14528.tar.gz
SMAPI-4adf8611131a5d86b15f017a42a0366837d14528.tar.bz2
SMAPI-4adf8611131a5d86b15f017a42a0366837d14528.zip
enable nullable annotations in the rest of SMAPI core (#837)
Diffstat (limited to 'src/SMAPI/Framework/ModLoading/AssemblyParseResult.cs')
-rw-r--r--src/SMAPI/Framework/ModLoading/AssemblyParseResult.cs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/SMAPI/Framework/ModLoading/AssemblyParseResult.cs b/src/SMAPI/Framework/ModLoading/AssemblyParseResult.cs
index 56bd5a8b..b133f8d6 100644
--- a/src/SMAPI/Framework/ModLoading/AssemblyParseResult.cs
+++ b/src/SMAPI/Framework/ModLoading/AssemblyParseResult.cs
@@ -1,5 +1,5 @@
-#nullable disable
-
+using System;
+using System.Diagnostics.CodeAnalysis;
using System.IO;
using Mono.Cecil;
@@ -15,11 +15,15 @@ namespace StardewModdingAPI.Framework.ModLoading
public readonly FileInfo File;
/// <summary>The assembly definition.</summary>
- public readonly AssemblyDefinition Definition;
+ public readonly AssemblyDefinition? Definition;
/// <summary>The result of the assembly load.</summary>
public AssemblyLoadStatus Status;
+ /// <summary>Whether the <see cref="Definition"/> is loaded and ready (i.e. the <see cref="Status"/> is not <see cref="AssemblyLoadStatus.AlreadyLoaded"/> or <see cref="AssemblyLoadStatus.Failed"/>).</summary>
+ [MemberNotNullWhen(true, nameof(AssemblyParseResult.Definition))]
+ public bool HasDefinition => this.Status == AssemblyLoadStatus.Okay;
+
/*********
** Public methods
@@ -28,11 +32,14 @@ namespace StardewModdingAPI.Framework.ModLoading
/// <param name="file">The original assembly file.</param>
/// <param name="assembly">The assembly definition.</param>
/// <param name="status">The result of the assembly load.</param>
- public AssemblyParseResult(FileInfo file, AssemblyDefinition assembly, AssemblyLoadStatus status)
+ public AssemblyParseResult(FileInfo file, AssemblyDefinition? assembly, AssemblyLoadStatus status)
{
this.File = file;
this.Definition = assembly;
this.Status = status;
+
+ if (status == AssemblyLoadStatus.Okay && assembly == null)
+ throw new InvalidOperationException($"Invalid assembly parse result: load status {status} with a null assembly.");
}
}
}