From 786f2177bd04992fa9af3ec516aa79603ef7993d Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 22 May 2024 14:33:45 -0400 Subject: [PATCH] Make implicit StringEventArgs bidirectional --- CHANGELIST.md | 1 + MPF.Core/Data/StringEventArgs.cs | 17 ++++++++++++++++- MPF.Core/DumpEnvironment.cs | 2 +- MPF.Core/Utilities/Logging.cs | 8 ++++---- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index eb157b20..a9c9c6d8 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -45,6 +45,7 @@ - Separate out StringEventArgs - Use StringEventArgs more broadly - Make StringEventArgs more complete +- Make implicit StringEventArgs bidirectional ### 3.1.9a (2024-05-21) diff --git a/MPF.Core/Data/StringEventArgs.cs b/MPF.Core/Data/StringEventArgs.cs index 6a67f13d..79ae6231 100644 --- a/MPF.Core/Data/StringEventArgs.cs +++ b/MPF.Core/Data/StringEventArgs.cs @@ -30,8 +30,23 @@ namespace MPF.Core.Data } /// - /// Results can be compared to boolean values based on the success value + /// Event arguments are just the value of the string contained within /// public static implicit operator string(StringEventArgs args) => args._value; + + /// + /// Event arguments are just the value of the string contained within + /// + public static implicit operator StringBuilder(StringEventArgs args) => new StringBuilder(args._value); + + /// + /// Event arguments are just the value of the string contained within + /// + public static implicit operator StringEventArgs(string? str) => new(str); + + /// + /// Event arguments are just the value of the string contained within + /// + public static implicit operator StringEventArgs(StringBuilder? sb) => new(sb); } } \ No newline at end of file diff --git a/MPF.Core/DumpEnvironment.cs b/MPF.Core/DumpEnvironment.cs index 90c770f4..69feb5e6 100644 --- a/MPF.Core/DumpEnvironment.cs +++ b/MPF.Core/DumpEnvironment.cs @@ -87,7 +87,7 @@ namespace MPF.Core /// /// Process the outputs in the queue /// - private void ProcessOutputs(string nextOutput) => ReportStatus?.Invoke(this, new StringEventArgs(nextOutput)); + private void ProcessOutputs(string nextOutput) => ReportStatus?.Invoke(this, nextOutput); #endregion diff --git a/MPF.Core/Utilities/Logging.cs b/MPF.Core/Utilities/Logging.cs index 3a915fd2..104816e7 100644 --- a/MPF.Core/Utilities/Logging.cs +++ b/MPF.Core/Utilities/Logging.cs @@ -65,7 +65,7 @@ namespace MPF.Core.Utilities catch { } finally { - handler?.Invoke(baseClass, new StringEventArgs(sb)); + handler?.Invoke(baseClass, sb); } } @@ -93,7 +93,7 @@ namespace MPF.Core.Utilities if (i == 0) { sb.Append(split[i]); - handler?.Invoke(baseClass, new StringEventArgs(sb)); + handler?.Invoke(baseClass, sb); sb = new(); } @@ -106,7 +106,7 @@ namespace MPF.Core.Utilities // For everything else, directly write out else { - handler?.Invoke(baseClass, new StringEventArgs(split[i])); + handler?.Invoke(baseClass, split[i]); } } } @@ -124,7 +124,7 @@ namespace MPF.Core.Utilities // Append and log the first sb.Append(split[0]); - handler?.Invoke(baseClass, new StringEventArgs(sb)); + handler?.Invoke(baseClass, sb); sb = new(); // Append the last