Skip to content

Remove code repetition in EventSourceSink.cs #10245

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions