diff --git a/CHANGELIST.md b/CHANGELIST.md index 29e41044..eb157b20 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -44,6 +44,7 @@ - Clean up usings - Separate out StringEventArgs - Use StringEventArgs more broadly +- Make StringEventArgs more complete ### 3.1.9a (2024-05-21) diff --git a/MPF.Core/Data/StringEventArgs.cs b/MPF.Core/Data/StringEventArgs.cs index 5ba5008b..6a67f13d 100644 --- a/MPF.Core/Data/StringEventArgs.cs +++ b/MPF.Core/Data/StringEventArgs.cs @@ -1,15 +1,37 @@ +using System; +using System.Text; + namespace MPF.Core.Data { /// /// String wrapper for event arguments /// - public class StringEventArgs : System.EventArgs + public class StringEventArgs : EventArgs { - public string? Value { get; set; } + /// + /// String represented by the event arguments + /// + private readonly string _value; + + /// + /// Constructor for string values + /// + public StringEventArgs(string? value) + { + _value = value ?? string.Empty; + } + + /// + /// Constructor for StringBuilder values + /// + public StringEventArgs(StringBuilder? value) + { + _value = value?.ToString() ?? string.Empty; + } /// /// Results can be compared to boolean values based on the success value /// - public static implicit operator string?(StringEventArgs args) => args.Value; + public static implicit operator string(StringEventArgs args) => args._value; } } \ No newline at end of file diff --git a/MPF.Core/DumpEnvironment.cs b/MPF.Core/DumpEnvironment.cs index 5995c900..90c770f4 100644 --- a/MPF.Core/DumpEnvironment.cs +++ b/MPF.Core/DumpEnvironment.cs @@ -82,12 +82,12 @@ namespace MPF.Core /// /// Event handler for data returned from a process /// - private void OutputToLog(object? proc, StringEventArgs args) => outputQueue?.Enqueue(args.Value); + private void OutputToLog(object? proc, StringEventArgs args) => outputQueue?.Enqueue(args); /// /// Process the outputs in the queue /// - private void ProcessOutputs(string nextOutput) => ReportStatus?.Invoke(this, new StringEventArgs { Value = nextOutput }); + private void ProcessOutputs(string nextOutput) => ReportStatus?.Invoke(this, new StringEventArgs(nextOutput)); #endregion diff --git a/MPF.Core/UI/ViewModels/MainViewModel.cs b/MPF.Core/UI/ViewModels/MainViewModel.cs index 2212976e..b4d1aa4e 100644 --- a/MPF.Core/UI/ViewModels/MainViewModel.cs +++ b/MPF.Core/UI/ViewModels/MainViewModel.cs @@ -1919,8 +1919,7 @@ namespace MPF.Core.UI.ViewModels { try { - value.Value ??= string.Empty; - LogLn(value.Value); + LogLn(value); } catch { } } diff --git a/MPF.Core/Utilities/Logging.cs b/MPF.Core/Utilities/Logging.cs index a302b0e7..3a915fd2 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 { Value = sb.ToString() }); + handler?.Invoke(baseClass, new StringEventArgs(sb)); } } @@ -93,7 +93,7 @@ namespace MPF.Core.Utilities if (i == 0) { sb.Append(split[i]); - handler?.Invoke(baseClass, new StringEventArgs { Value = sb.ToString() }); + handler?.Invoke(baseClass, new StringEventArgs(sb)); sb = new(); } @@ -106,7 +106,7 @@ namespace MPF.Core.Utilities // For everything else, directly write out else { - handler?.Invoke(baseClass, new StringEventArgs { Value = split[i] }); + handler?.Invoke(baseClass, new StringEventArgs(split[i])); } } } @@ -124,7 +124,7 @@ namespace MPF.Core.Utilities // Append and log the first sb.Append(split[0]); - handler?.Invoke(baseClass, new StringEventArgs { Value = sb.ToString() }); + handler?.Invoke(baseClass, new StringEventArgs(sb)); sb = new(); // Append the last