From 889004f1eba31aa3a5069e1dcbe79896d05720b0 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 19 Apr 2022 19:03:47 -0400 Subject: move deprecation code into namespace --- .../Framework/Deprecations/DeprecationWarning.cs | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/SMAPI/Framework/Deprecations/DeprecationWarning.cs (limited to 'src/SMAPI/Framework/Deprecations/DeprecationWarning.cs') diff --git a/src/SMAPI/Framework/Deprecations/DeprecationWarning.cs b/src/SMAPI/Framework/Deprecations/DeprecationWarning.cs new file mode 100644 index 00000000..38062daf --- /dev/null +++ b/src/SMAPI/Framework/Deprecations/DeprecationWarning.cs @@ -0,0 +1,48 @@ +using System.Diagnostics; + +namespace StardewModdingAPI.Framework.Deprecations +{ + /// A deprecation warning for a mod. + internal class DeprecationWarning + { + /********* + ** Accessors + *********/ + /// The affected mod. + public IModMetadata? Mod { get; } + + /// Get the display name for the affected mod. + public string ModName => this.Mod?.DisplayName ?? ""; + + /// A noun phrase describing what is deprecated. + public string NounPhrase { get; } + + /// The SMAPI version which deprecated it. + public string Version { get; } + + /// The deprecation level for the affected code. + public DeprecationLevel Level { get; } + + /// The stack trace when the deprecation warning was raised. + public StackTrace StackTrace { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The affected mod. + /// A noun phrase describing what is deprecated. + /// The SMAPI version which deprecated it. + /// The deprecation level for the affected code. + /// The stack trace when the deprecation warning was raised. + public DeprecationWarning(IModMetadata? mod, string nounPhrase, string version, DeprecationLevel level, StackTrace stackTrace) + { + this.Mod = mod; + this.NounPhrase = nounPhrase; + this.Version = version; + this.Level = level; + this.StackTrace = stackTrace; + } + } +} -- cgit From e6c696fa6b0bfe5ef013e1179765ce1dcb071c38 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 19 Apr 2022 19:11:58 -0400 Subject: add immutable stack trace to cache stack info --- src/SMAPI/Framework/Deprecations/DeprecationWarning.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/SMAPI/Framework/Deprecations/DeprecationWarning.cs') diff --git a/src/SMAPI/Framework/Deprecations/DeprecationWarning.cs b/src/SMAPI/Framework/Deprecations/DeprecationWarning.cs index 38062daf..e00881b1 100644 --- a/src/SMAPI/Framework/Deprecations/DeprecationWarning.cs +++ b/src/SMAPI/Framework/Deprecations/DeprecationWarning.cs @@ -24,7 +24,7 @@ namespace StardewModdingAPI.Framework.Deprecations public DeprecationLevel Level { get; } /// The stack trace when the deprecation warning was raised. - public StackTrace StackTrace { get; } + public ImmutableStackTrace StackTrace { get; } /********* @@ -36,7 +36,7 @@ namespace StardewModdingAPI.Framework.Deprecations /// The SMAPI version which deprecated it. /// The deprecation level for the affected code. /// The stack trace when the deprecation warning was raised. - public DeprecationWarning(IModMetadata? mod, string nounPhrase, string version, DeprecationLevel level, StackTrace stackTrace) + public DeprecationWarning(IModMetadata? mod, string nounPhrase, string version, DeprecationLevel level, ImmutableStackTrace stackTrace) { this.Mod = mod; this.NounPhrase = nounPhrase; -- cgit From 7bb7a7522fcdfef27f8f22ba77f24c7609f49912 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 30 Apr 2022 12:57:28 -0400 Subject: omit stack trace for deprecated code not called directly by the mod --- src/SMAPI/Framework/Deprecations/DeprecationWarning.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/SMAPI/Framework/Deprecations/DeprecationWarning.cs') diff --git a/src/SMAPI/Framework/Deprecations/DeprecationWarning.cs b/src/SMAPI/Framework/Deprecations/DeprecationWarning.cs index e00881b1..5936517b 100644 --- a/src/SMAPI/Framework/Deprecations/DeprecationWarning.cs +++ b/src/SMAPI/Framework/Deprecations/DeprecationWarning.cs @@ -1,5 +1,3 @@ -using System.Diagnostics; - namespace StardewModdingAPI.Framework.Deprecations { /// A deprecation warning for a mod. @@ -26,6 +24,9 @@ namespace StardewModdingAPI.Framework.Deprecations /// The stack trace when the deprecation warning was raised. public ImmutableStackTrace StackTrace { get; } + /// Whether to log a stack trace showing where the deprecated code is in the mod. + public bool LogStackTrace { get; } + /********* ** Public methods @@ -36,13 +37,15 @@ namespace StardewModdingAPI.Framework.Deprecations /// The SMAPI version which deprecated it. /// The deprecation level for the affected code. /// The stack trace when the deprecation warning was raised. - public DeprecationWarning(IModMetadata? mod, string nounPhrase, string version, DeprecationLevel level, ImmutableStackTrace stackTrace) + /// Whether to log a stack trace showing where the deprecated code is in the mod. + public DeprecationWarning(IModMetadata? mod, string nounPhrase, string version, DeprecationLevel level, ImmutableStackTrace stackTrace, bool logStackTrace) { this.Mod = mod; this.NounPhrase = nounPhrase; this.Version = version; this.Level = level; this.StackTrace = stackTrace; + this.LogStackTrace = logStackTrace; } } } -- cgit