Skip to content

Remove code repetition in EventSourceSink.cs #10245

@JanKrivanek

Description

@JanKrivanek

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);
    }
    ...
}

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions