Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: prepare serialization infrastructure for .NET 8+ #1034

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<DefineConstants Condition="'$(TargetFramework)' == 'net7.0' OR '$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net5.0'">$(DefineConstants);FEATURE_FILE_MOVE_WITH_OVERWRITE;FEATURE_SUPPORTED_OS_ATTRIBUTE;FEATURE_FILE_SYSTEM_WATCHER_FILTERS;FEATURE_ENDS_IN_DIRECTORY_SEPARATOR;FEATURE_PATH_JOIN_WITH_PARAMS;FEATURE_PATH_JOIN_WITH_FOUR_PATHS</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'net7.0' OR '$(TargetFramework)' == 'net6.0'">$(DefineConstants);FEATURE_FILE_SYSTEM_INFO_LINK_TARGET;FEATURE_CREATE_SYMBOLIC_LINK;FEATURE_FILESTREAM_OPTIONS</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'net7.0'">$(DefineConstants);FEATURE_PATH_EXISTS;FEATURE_FILE_SYSTEM_WATCHER_WAIT_WITH_TIMESPAN;FEATURE_FILE_ATTRIBUTES_VIA_HANDLE;FEATURE_CREATE_TEMP_SUBDIRECTORY;FEATURE_READ_LINES_ASYNC;FEATURE_UNIX_FILE_MODE</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_SERIALIZABLE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.133">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ namespace System.IO.Abstractions.TestingHelpers


/// <inheritdoc />

#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class MockDirectory : DirectoryBase
{
private readonly IMockFileDataAccessor mockFileDataAccessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
namespace System.IO.Abstractions.TestingHelpers
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class MockDirectoryData : MockFileData
{

#if FEATURE_SERIALIZABLE
[NonSerialized]
#endif
private DirectorySecurity accessControl;

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace System.IO.Abstractions.TestingHelpers
using XFS = MockUnixSupport;

/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class MockDirectoryInfo : DirectoryInfoBase, IFileSystemAclSupport
{
private readonly IMockFileDataAccessor mockFileDataAccessor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace System.IO.Abstractions.TestingHelpers
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class MockDirectoryInfoFactory : IDirectoryInfoFactory
{
readonly IMockFileDataAccessor mockFileSystem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace System.IO.Abstractions.TestingHelpers
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class MockDriveInfo : DriveInfoBase
{
private readonly IMockFileDataAccessor mockFileDataAccessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace System.IO.Abstractions.TestingHelpers
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class MockDriveInfoFactory : IDriveInfoFactory
{
private readonly IMockFileDataAccessor mockFileSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace System.IO.Abstractions.TestingHelpers
using XFS = MockUnixSupport;

/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public partial class MockFile : FileBase
{
private readonly IMockFileDataAccessor mockFileDataAccessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace System.IO.Abstractions.TestingHelpers
/// <summary>
/// The class represents the associated data of a file.
/// </summary>
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class MockFileData
{
/// <summary>
Expand Down Expand Up @@ -36,7 +38,9 @@ public class MockFileData
/// <summary>
/// The access control of the <see cref="MockFileData"/>.
/// </summary>
#if FEATURE_SERIALIZABLE
[NonSerialized]
#endif
private FileSecurity accessControl;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
namespace System.IO.Abstractions.TestingHelpers
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class MockFileInfo : FileInfoBase, IFileSystemAclSupport
{
private readonly IMockFileDataAccessor mockFileSystem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace System.IO.Abstractions.TestingHelpers
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class MockFileInfoFactory : IFileInfoFactory
{
private readonly IMockFileDataAccessor mockFileSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
namespace System.IO.Abstractions.TestingHelpers
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class MockFileStream : FileSystemStream, IFileSystemAclSupport
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
namespace System.IO.Abstractions.TestingHelpers
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class MockFileStreamFactory : IFileStreamFactory
{
private readonly IMockFileDataAccessor mockFileSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ namespace System.IO.Abstractions.TestingHelpers
using XFS = MockUnixSupport;

/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class MockFileSystem : FileSystemBase, IMockFileDataAccessor
{
private const string DEFAULT_CURRENT_DIRECTORY = @"C:\";
private const string TEMP_DIRECTORY = @"C:\temp";

private readonly IDictionary<string, FileSystemEntry> files;
private readonly PathVerifier pathVerifier;
#if FEATURE_SERIALIZABLE
[NonSerialized]
#endif
private Func<DateTime> dateTimeProvider = defaultDateTimeProvider;
private static Func<DateTime> defaultDateTimeProvider = () => DateTime.UtcNow;

Expand Down Expand Up @@ -516,7 +520,9 @@ private bool FileIsReadOnly(string path)
return (GetFile(path).Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
}

[Serializable]
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
private class FileSystemEntry
{
public string Path { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace System.IO.Abstractions.TestingHelpers
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class MockFileSystemWatcherFactory : IFileSystemWatcherFactory
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ namespace System.IO.Abstractions.TestingHelpers
/// <summary>
/// PathWrapper calls direct to Path but all this does is string manipulation so we can inherit directly from PathWrapper as no IO is done
/// </summary>
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class MockPath : PathWrapper
{
private readonly IMockFileDataAccessor mockFileDataAccessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ namespace System.IO.Abstractions.TestingHelpers
/// <summary>
/// Provides helper methods for verifying paths.
/// </summary>
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class PathVerifier
{
private static readonly char[] AdditionalInvalidPathChars = { '*', '?' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
/// <summary>
/// Provides operations against path strings dependeing on the case-senstivity of the runtime platform.
/// </summary>
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class StringOperations
{
private readonly bool caseSensitive;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace System.IO.Abstractions
{
/// <inheritdoc cref="Directory"/>
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public abstract class DirectoryBase : IDirectory
{
/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
namespace System.IO.Abstractions
{
/// <inheritdoc cref="IDirectoryInfo"/>
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public abstract class DirectoryInfoBase : FileSystemInfoBase, IDirectoryInfo
{
/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace System.IO.Abstractions
{
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
internal class DirectoryInfoFactory : IDirectoryInfoFactory
{
private readonly IFileSystem fileSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
namespace System.IO.Abstractions
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class DirectoryInfoWrapper : DirectoryInfoBase, IFileSystemAclSupport
{
private readonly DirectoryInfo instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
namespace System.IO.Abstractions
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class DirectoryWrapper : DirectoryBase
{
/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace System.IO.Abstractions
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public abstract class DriveInfoBase : IDriveInfo
{
/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace System.IO.Abstractions
{
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
internal class DriveInfoFactory : IDriveInfoFactory
{
private readonly IFileSystem fileSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace System.IO.Abstractions
/// <summary>
/// The wrapper for a <see cref="DriveInfo"/>.
/// </summary>
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class DriveInfoWrapper : DriveInfoBase
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/TestableIO.System.IO.Abstractions.Wrappers/FileBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace System.IO.Abstractions
{
/// <inheritdoc cref="File"/>
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public abstract partial class FileBase : IFile
{
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace System.IO.Abstractions
{
/// <inheritdoc cref="FileInfo"/>
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public abstract class FileInfoBase : FileSystemInfoBase, IFileInfo
{
/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace System.IO.Abstractions
{
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
internal class FileInfoFactory : IFileInfoFactory
{
private readonly IFileSystem fileSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
namespace System.IO.Abstractions
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class FileInfoWrapper : FileInfoBase, IFileSystemAclSupport
{
private readonly FileInfo instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace System.IO.Abstractions
{
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
internal sealed class FileStreamFactory : IFileStreamFactory
{
public FileStreamFactory(IFileSystem fileSystem)
Expand Down
2 changes: 2 additions & 0 deletions src/TestableIO.System.IO.Abstractions.Wrappers/FileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace System.IO.Abstractions
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class FileSystem : FileSystemBase
{
/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace System.IO.Abstractions
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public abstract class FileSystemBase : IFileSystem
{
/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace System.IO.Abstractions
{
/// <inheritdoc cref="FileSystemInfo"/>
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public abstract class FileSystemInfoBase : IFileSystemInfo
{
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace System.IO.Abstractions
{
/// <inheritdoc cref="FileSystemWatcher"/>
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public abstract class FileSystemWatcherBase : IFileSystemWatcher
{
/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace System.IO.Abstractions
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class FileSystemWatcherFactory : IFileSystemWatcherFactory
{
///
Expand Down
Loading
Loading