msbuild
msbuild copied to clipboard
Remove code repetition in EventSourceSink.cs
Context
There is large code repetition created by copy pasting the event handlers invoking
https://github.com/dotnet/msbuild/blob/main/src/Build/BackEnd/Components/Logging/EventSourceSink.cs#L321-L977
We should be able to easily extract tho code using generic delegates and reduce the size of class significantly
Impact
Engineering only - reduced codebase size (hence easier reading and lower chance for errors during mechanical copy-pasting)
How to
public delegate void ArgsHandler<in TArgs>(object sender, TArgs e) where TArgs : BuildEventArgs;
ArgsHandler<BuildMessageEventArgs> handler = (o, args) => MessageRaised?.Invoke(o, args);
private void RaiseEvent<TArgs>(object sender, TArgs buildEvent, ArgsHandler<TArgs> handler) where TArgs : BuildEventArgs
{
try
{
handler(sender, buildEvent);
}
...
}