From 0b48c1748b354458059c7607415288de072b01e9 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 12 Apr 2022 19:15:39 -0400 Subject: enable nullable annotations in the web project & related code (#837) --- src/SMAPI.Web/Framework/Storage/StoredFileInfo.cs | 41 +++++++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'src/SMAPI.Web/Framework/Storage/StoredFileInfo.cs') diff --git a/src/SMAPI.Web/Framework/Storage/StoredFileInfo.cs b/src/SMAPI.Web/Framework/Storage/StoredFileInfo.cs index cd941c94..bbbcf2a9 100644 --- a/src/SMAPI.Web/Framework/Storage/StoredFileInfo.cs +++ b/src/SMAPI.Web/Framework/Storage/StoredFileInfo.cs @@ -1,25 +1,52 @@ -#nullable disable - using System; +using System.Diagnostics.CodeAnalysis; namespace StardewModdingAPI.Web.Framework.Storage { /// The response for a get-file request. internal class StoredFileInfo { + /********* + ** Accessors + *********/ /// Whether the file was successfully fetched. - public bool Success { get; set; } + [MemberNotNullWhen(true, nameof(StoredFileInfo.Content))] + public bool Success => this.Content != null && this.Error == null; /// The fetched file content (if is true). - public string Content { get; set; } + public string? Content { get; } /// When the file will no longer be available. - public DateTime? Expiry { get; set; } + public DateTimeOffset? Expiry { get; } /// The error message if saving succeeded, but a non-blocking issue was encountered. - public string Warning { get; set; } + public string? Warning { get; } /// The error message if saving failed. - public string Error { get; set; } + public string? Error { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The fetched file content (if is true). + /// When the file will no longer be available. + /// The error message if saving succeeded, but a non-blocking issue was encountered. + /// The error message if saving failed. + public StoredFileInfo(string? content, DateTimeOffset? expiry, string? warning = null, string? error = null) + { + this.Content = content; + this.Expiry = expiry; + this.Warning = warning; + this.Error = error; + } + + /// Construct an instance. + /// The error message if saving failed. + public StoredFileInfo(string error) + { + this.Error = error; + } } } -- cgit