Repository: dotnet/runtime
File: src/libraries/System.IO.FileSystem.Watcher/tests/Utility/FileSystemWatcherTest.cs (C#)

Code before:
            }
            finally
            {
                watcher.Changed -= fileWatcherEvent;
                watcher.Created -= fileWatcherEvent;
                watcher.Deleted -= fileWatcherEvent;
                watcher.Renamed -= renameWatcherEvent;
                watcher.Error -= errorHandler;
                watcher.EnableRaisingEvents = raisingEvent;
            }

            if (error != null)
            {
                Assert.Fail($"Filewatcher error event triggered: { error.GetException()?.Message ?? "Unknow error" }");
            }

            return events;

            void AddEvent(WatcherChangeTypes eventType, string dir1, string dir2 = "")
            {
                var firedEvent = new FiredEvent(eventType, dir1, dir2);
                if (!filter(firedEvent))
                {
                    return;
                }

                events.Add(new FiredEvent(eventType, dir1, dir2));
                if (Interlocked.Increment(ref eventsOrrures) == expectedEvents)
                {
                    eventsOccurred.Set();
                }
            }
        }

        internal class TestISynchronizeInvoke : ISynchronizeInvoke
        {
            public bool BeginInvoke_Called;
            public Delegate ExpectedDelegate;

            public IAsyncResult BeginInvoke(Delegate method, object[] args)
            {
                if (ExpectedDelegate != null)
                    Assert.Equal(ExpectedDelegate, method);

                BeginInvoke_Called = true;
                method.DynamicInvoke(args[0], args[1]);
                return null;
            }

            public bool InvokeRequired => true;
            public object EndInvoke(IAsyncResult result) => null;

Review comment (suggestion):
As it is, "filter" as a verb does not connote to me what its return value will be. I suggest inverting boolean here and renaming the param so this can read:

```suggestion
                if (isFilteredOut(firedEvent))
                {
                    return;
                }

```

Code after:
            }
            finally
            {
                watcher.Changed -= fileWatcherEvent;
                watcher.Created -= fileWatcherEvent;
                watcher.Deleted -= fileWatcherEvent;
                watcher.Renamed -= renameWatcherEvent;
                watcher.Error -= errorHandler;
                watcher.EnableRaisingEvents = raisingEvent;
            }

            if (error != null)
            {
                Assert.Fail($"Filewatcher error event triggered: { error.GetException()?.Message ?? "Unknow error" }");
            }

            return events;

            void AddEvent(WatcherChangeTypes eventType, string dir1, string dir2 = "")
            {
                var firedEvent = new FiredEvent(eventType, dir1, dir2);
                if (isFilteredOut(firedEvent))
                {
                    return;
                }

                events.Add(firedEvent);
                if (Interlocked.Increment(ref eventsOrrures) == expectedEvents)
                {
                    eventsOccurred.Set();
                }
            }
        }

        internal class TestISynchronizeInvoke : ISynchronizeInvoke
        {
            public bool BeginInvoke_Called;
            public Delegate ExpectedDelegate;

            public IAsyncResult BeginInvoke(Delegate method, object[] args)
            {
                if (ExpectedDelegate != null)
                    Assert.Equal(ExpectedDelegate, method);

                BeginInvoke_Called = true;
                method.DynamicInvoke(args[0], args[1]);
                return null;
            }

            public bool InvokeRequired => true;
            public object EndInvoke(IAsyncResult result) => null;