Make StringEventArgs more complete

This commit is contained in:
Matt Nadareski
2024-05-22 14:29:37 -04:00
parent b39542b651
commit ddaf5e35f3
5 changed files with 33 additions and 11 deletions

View File

@@ -44,6 +44,7 @@
- Clean up usings
- Separate out StringEventArgs
- Use StringEventArgs more broadly
- Make StringEventArgs more complete
### 3.1.9a (2024-05-21)

View File

@@ -1,15 +1,37 @@
using System;
using System.Text;
namespace MPF.Core.Data
{
/// <summary>
/// String wrapper for event arguments
/// </summary>
public class StringEventArgs : System.EventArgs
public class StringEventArgs : EventArgs
{
public string? Value { get; set; }
/// <summary>
/// String represented by the event arguments
/// </summary>
private readonly string _value;
/// <summary>
/// Constructor for string values
/// </summary>
public StringEventArgs(string? value)
{
_value = value ?? string.Empty;
}
/// <summary>
/// Constructor for StringBuilder values
/// </summary>
public StringEventArgs(StringBuilder? value)
{
_value = value?.ToString() ?? string.Empty;
}
/// <summary>
/// Results can be compared to boolean values based on the success value
/// </summary>
public static implicit operator string?(StringEventArgs args) => args.Value;
public static implicit operator string(StringEventArgs args) => args._value;
}
}

View File

@@ -82,12 +82,12 @@ namespace MPF.Core
/// <summary>
/// Event handler for data returned from a process
/// </summary>
private void OutputToLog(object? proc, StringEventArgs args) => outputQueue?.Enqueue(args.Value);
private void OutputToLog(object? proc, StringEventArgs args) => outputQueue?.Enqueue(args);
/// <summary>
/// Process the outputs in the queue
/// </summary>
private void ProcessOutputs(string nextOutput) => ReportStatus?.Invoke(this, new StringEventArgs { Value = nextOutput });
private void ProcessOutputs(string nextOutput) => ReportStatus?.Invoke(this, new StringEventArgs(nextOutput));
#endregion

View File

@@ -1919,8 +1919,7 @@ namespace MPF.Core.UI.ViewModels
{
try
{
value.Value ??= string.Empty;
LogLn(value.Value);
LogLn(value);
}
catch { }
}

View File

@@ -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