Skip to content

Commit d8dd8da

Browse files
rameelteo-tsirpanisstephentoub
authored
Skip adding NullChangeToken instances to the composite list (#115684)
* Skip adding NullChangeToken instances to the composite list * Address feedback Co-authored-by: Theodore Tsirpanis <[email protected]> --------- Co-authored-by: Theodore Tsirpanis <[email protected]> Co-authored-by: Stephen Toub <[email protected]>
1 parent 02ac51e commit d8dd8da

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/libraries/Microsoft.Extensions.FileProviders.Composite/src/CompositeFileProvider.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,18 @@ public IChangeToken Watch(string pattern)
8080
foreach (IFileProvider fileProvider in _fileProviders)
8181
{
8282
IChangeToken changeToken = fileProvider.Watch(pattern);
83-
if (changeToken != null)
83+
if (changeToken is not (null or NullChangeToken))
8484
{
8585
changeTokens.Add(changeToken);
8686
}
8787
}
8888

89-
// There is no change token with active change callbacks
90-
if (changeTokens.Count == 0)
89+
return changeTokens.Count switch
9190
{
92-
return NullChangeToken.Singleton;
93-
}
94-
95-
return new CompositeChangeToken(changeTokens);
91+
0 => NullChangeToken.Singleton,
92+
1 => changeTokens[0],
93+
_ => new CompositeChangeToken(changeTokens)
94+
};
9695
}
9796

9897
/// <summary>

0 commit comments

Comments
 (0)