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

feat: Add Name to IFile.Create (and others) #793

Conversation

BrianMcBrayer
Copy link
Contributor

Added draft implementation of a FileStream-like class It is not plumbed in at all because I want to discuss the approach first.

@fgreinacher is this kind of what you were thinking in #779 ? I figured if this is correct, I can go through and update all the related Stream references to return FileStream with the Name property properly set.

@BrianMcBrayer BrianMcBrayer changed the title Add Name to IFile.Create (and others) feat: Add Name to IFile.Create (and others) Jan 8, 2022
@BrianMcBrayer
Copy link
Contributor Author

Just for reference, there are a few other fields that I am not sure I want to tackle now that we could eventually add here:

  • Handle (obsolete)
  • IsAsync - Gets a value that indicates whether the FileStream was opened asynchronously or synchronously
  • SafeFileHandle - Gets a SafeFileHandle object that represents the operating system file handle for the file that the current FileStream object encapsulates

(see https://docs.microsoft.com/en-us/dotnet/api/system.io.filestream?view=net-6.0#properties)

@fgreinacher
Copy link
Contributor

@fgreinacher is this kind of what you were thinking in #779 ? I figured if this is correct, I can go through and update all the related Stream references to return FileStream with the Name property properly set.

Yes, that's what I had In mind, thanks for taking care!

/// <summary>
/// A <see cref="Stream"/> that has properties similar to <see cref="System.IO.FileStream"/>
/// </summary>
public class FileStream : Stream
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use another name for this to prevent conflicts with System.IO.FileStream.

I don't have a good idea, maybe FileStreamBase to mirror other types here?

@fgreinacher
Copy link
Contributor

Just for reference, there are a few other fields that I am not sure I want to tackle now that we could eventually add here:

  • Handle (obsolete)
  • IsAsync - Gets a value that indicates whether the FileStream was opened asynchronously or synchronously
  • SafeFileHandle - Gets a SafeFileHandle object that represents the operating system file handle for the file that the current FileStream object encapsulates

(see https://docs.microsoft.com/en-us/dotnet/api/system.io.filestream?view=net-6.0#properties)

I think we can ignore Handle and SafeFileHandle as these would be impossible to mock in a useful way. I'm unsure about IsAsync - do you have an idea what this is commonly used for?

…umbed in at all because I want to discuss the approach first.
@BrianMcBrayer BrianMcBrayer force-pushed the feature/add-file-stream-like-stream branch from e7c380e to 461f370 Compare January 10, 2022 15:48
@BrianMcBrayer
Copy link
Contributor Author

Just for reference, there are a few other fields that I am not sure I want to tackle now that we could eventually add here:

  • Handle (obsolete)
  • IsAsync - Gets a value that indicates whether the FileStream was opened asynchronously or synchronously
  • SafeFileHandle - Gets a SafeFileHandle object that represents the operating system file handle for the file that the current FileStream object encapsulates

(see https://docs.microsoft.com/en-us/dotnet/api/system.io.filestream?view=net-6.0#properties)

I think we can ignore Handle and SafeFileHandle as these would be impossible to mock in a useful way. I'm unsure about IsAsync - do you have an idea what this is commonly used for?

IsAsync is something that can be specified when opening a file that will hint to the system whether IO should be on a ThreadPool thread or not. I'm not very familiar with it.

I think I should add it anyway, since it's just a pass-through property and it's readonly. I'll do that and the other things in the review today, and then I'll start wiring this in.

mergify bot pushed a commit that referenced this pull request Nov 14, 2022
Make the following changes for the interfaces:
1. Enable [Nullable reference types](https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references)
2. Improve and cleanup XML documentation and sort properties and methods in interfaces alphabetically
3. Consolidate the naming in the factory methods to always use just `New`; so instead of `new DirectoryInfo(path)` you should use `IFileSystem.DirectoryInfo.New(path)`. The previous existing factory methods were kept and marked as `Obsolete`.
4. Added a `Wrap` method to the factory interfaces that can be used instead of a direct cast (which is not possible for interfaces) to create a wrapped interface from a "System.IO" type.
5. Removed the `WriteAllLinesAsync` with array overload, as it is not defined in `System.IO` and overload resolution will automatically use the `IEnumerable` overload.
6. Added missing methods: `ResolveLinkTarget` and `CreateAsSymbolicLink`
7. Change the return type for Stream-Methods to a custom defined `FileSystemStream`.
   *Note: This should fix the issues from #793 , right?*

Added the following extensibility measures:
- Add `IFileSystem FileSystem` property to more classes to enable implementing extension methods.
  This was simplified by adding a base interface `IFileSystemExtensionPoint`
- Add a `IFileSystemExtensibility Extensibility` property on `IFileSystemInfo` and `IFileSystemStream` which grants access to the underlying wrapped instance or to a metadata dictionary to store additional information together with the instance.
@vbreuss
Copy link
Member

vbreuss commented Apr 10, 2023

I think this pull request could be closed, as it is now implemented as FileSystemStream in #906.
Do you agree, @BrianMcBrayer ?

@BrianMcBrayer
Copy link
Contributor Author

I agree. I feel bad I did not get around to getting this PR in when it was needed 😬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants