Skip to content

Commit 8188a7b

Browse files
committed
Expose FileSystemWatcher.Filters Property
Introduced in dotnet core 3.0, FileSystemWatcher has a property which allows multiple filters to exist on a single instance. https://docs.microsoft.com/en-us/dotnet/api/system.io.filesystemwatcher.filters?view=net-6.0
1 parent 8f92d45 commit 8188a7b

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

Source/FileWatcherEx/FileSystemWatcherEx.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,26 @@ public class FileSystemWatcherEx : IDisposable
3131
public string FolderPath { get; set; } = "";
3232

3333

34+
/// <summary>
35+
/// The collection of all the filters used to determine what files are monitored in a directory.
36+
/// </summary>
37+
public System.Collections.ObjectModel.Collection<string> Filters { get; } = new();
38+
39+
3440
/// <summary>
3541
/// Filter string used for determining what files are monitored in a directory
3642
/// </summary>
37-
public string Filter { get; set; } = "*.*";
43+
public string Filter {
44+
get
45+
{
46+
return Filters.Count == 0 ? "*" : Filters[0];
47+
}
48+
set
49+
{
50+
Filters.Clear();
51+
Filters.Add(value);
52+
}
53+
}
3854

3955

4056
/// <summary>
@@ -213,7 +229,12 @@ void onError(ErrorEventArgs e)
213229
_watcher = new FileWatcher();
214230

215231
_fsw = _watcher.Create(FolderPath, onEvent, onError);
216-
_fsw.Filter = Filter;
232+
233+
foreach(var filter in Filters)
234+
{
235+
_fsw.Filters.Add(filter);
236+
}
237+
217238
_fsw.NotifyFilter = NotifyFilter;
218239
_fsw.IncludeSubdirectories = IncludeSubdirectories;
219240
_fsw.SynchronizingObject = SynchronizingObject;

0 commit comments

Comments
 (0)