Skip to content

Commit 1b567e8

Browse files
committed
Avoid null for dateTimeProvider when deserializing
1 parent e60ff0b commit 1b567e8

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎src/System.IO.Abstractions.TestingHelpers/MockFileSystem.cs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using System.Collections.Generic;
1+
 using System.Collections.Generic;
22
using System.Linq;
33
using System.Reflection;
4+
using System.Runtime.Serialization;
45

56
namespace System.IO.Abstractions.TestingHelpers
67
{
@@ -143,7 +144,7 @@ private string GetPathWithCorrectDirectoryCapitalization(string fullPath)
143144
/// <inheritdoc />
144145
public MockFileData AdjustTimes(MockFileData fileData, TimeAdjustments timeAdjustments)
145146
{
146-
var now = (dateTimeProvider ?? defaultDateTimeProvider)();
147+
var now = dateTimeProvider();
147148
if ((timeAdjustments & TimeAdjustments.CreationTime) != TimeAdjustments.None)
148149
{
149150
fileData.CreationTime = now;
@@ -414,6 +415,12 @@ public IEnumerable<string> AllDirectories
414415
}
415416
}
416417

418+
[OnDeserializing]
419+
private void OnDeserializing(StreamingContext c)
420+
{
421+
dateTimeProvider = defaultDateTimeProvider;
422+
}
423+
417424
private bool AnyFileIsReadOnly(string path)
418425
{
419426
return Directory.GetFiles(path).Any(file => FileIsReadOnly(file));

0 commit comments

Comments
 (0)