Make implicit StringEventArgs bidirectional

This commit is contained in:
Matt Nadareski
2024-05-22 14:33:45 -04:00
parent ddaf5e35f3
commit 786f2177bd
4 changed files with 22 additions and 6 deletions

View File

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

View File

@@ -30,8 +30,23 @@ namespace MPF.Core.Data
}
/// <summary>
/// Results can be compared to boolean values based on the success value
/// Event arguments are just the value of the string contained within
/// </summary>
public static implicit operator string(StringEventArgs args) => args._value;
/// <summary>
/// Event arguments are just the value of the string contained within
/// </summary>
public static implicit operator StringBuilder(StringEventArgs args) => new StringBuilder(args._value);
/// <summary>
/// Event arguments are just the value of the string contained within
/// </summary>
public static implicit operator StringEventArgs(string? str) => new(str);
/// <summary>
/// Event arguments are just the value of the string contained within
/// </summary>
public static implicit operator StringEventArgs(StringBuilder? sb) => new(sb);
}
}

View File

@@ -87,7 +87,7 @@ namespace MPF.Core
/// <summary>
/// Process the outputs in the queue
/// </summary>
private void ProcessOutputs(string nextOutput) => ReportStatus?.Invoke(this, new StringEventArgs(nextOutput));
private void ProcessOutputs(string nextOutput) => ReportStatus?.Invoke(this, nextOutput);
#endregion

View File

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