c# - 创建 FileStream.Open c# 的接口(interface)

标签 c# .net

我正在尝试创建 FileStream.Open 方法的接口(interface)。我已经开始了,但有点困惑:

public interface IFileDataSource
{
    FileStream Open(string path,
                 FileMode mode,
                 FileAccess access,
                 FileShare share);
}

我需要包装 this is another class 才能使用这个接口(interface)吗?

最佳答案

您不需要“包装”它 - 但您确实需要实现它才能使用它。假设您会编写一个简单的实现,它只委托(delegate)给 File.Open:

public class BclFileDataSource : IFileDataSource
{
    public FileStream Open(string path,
                           FileMode mode,
                           FileAccess access,
                           FileShare share)
    {
        return File.Open(path, mode, access, share);
    }
}

关于c# - 创建 FileStream.Open c# 的接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11186122/

相关文章:

c++ - 混合模式进程与托管到非托管 IPC

c# - UWP 框架导航

c# - 组件已注册,但仍在等待依赖项

c# - 使用 BeginInvoke 时有没有办法确定执行处理程序的线程?

c# - 统一: Change default lifetime manager for implicit registrations and/or disable them

.net - http ://schemas. microsoft.com/winfx/2006/xaml/presentation 的架构文件的位置在哪里?

c# - 延迟过滤列表

c# - 在 Xamarin.Mac 中使用 SQLite-Net 扩展和 SQLiteConnection

c# - EF 核心 2、.NET 核心 2 :How do I query the same column for multiple conditions using IQueryable<T>?

c# - 通过远程桌面连接时出现 IValueConverter NullReferenceException