将 MemoryStream 与需要 Filestream 的函数一起使用

发布于 2024-07-11 23:41:30 字数 159 浏览 8 评论 0原文

我这里有一些函数,例如,它们被定义为

private int WriteLogikParameterTyp(FileStream filestream)

我无法更改。 我希望它们写入 MemoryStream 对象。 这可能吗?

I have some functions here that for example are defined as

private int WriteLogikParameterTyp(FileStream filestream)

which i can not change. I want them to write into a MemoryStream Object. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

不一样的天空 2024-07-18 23:41:30

不,

FileStream 是一个具体的实现。

但它是一个私有方法,因此应该很容易更改,因为您可以找到所有内部用途? 建议用 Stream 而不是 FileStream 替换方法签名。

好吧...除非您创建一个临时文件,否则将其写入然后将其读入内存。

No.

FileStream is a concrete implementation.

But it's a private method so should be easy enough to change since you can find all internal uses? Suggest replacing method signature with Stream rather than FileStream.

Well... unless you create a tempory file, write to it then read it into memory.

∝单色的世界 2024-07-18 23:41:30

由于您无法更改函数签名以接受更通用的类型。我建议写入临时文件,然后将内容读入 MemoryStream 实例。

Since you can't change the function signature to accept a more generic type.. I'd suggest writing out to a temporary file and then reading the contents into a MemoryStream instance.

來不及說愛妳 2024-07-18 23:41:30

否。

如果您无权访问它们,您可以使用 Reflector 来了解它们的工作原理并实现您自己的 MemoryStream 版本。 这是否合法是另一回事......

No.

If you do not have access to them, you could use reflector to find out how they work and implement your own version for a MemoryStream. Whether this is legal is another matter...

肥爪爪 2024-07-18 23:41:30

不可以。FileStream 不公开可调用的构造函数,因此您无法继承它来模拟它。

No. FileStream doesn't expose a constructor that can be called so you can't inherit from it in order to emulate it.

老街孤人 2024-07-18 23:41:30

建议;

像这样重命名该方法

private int WriteLogikParameterTyp_Ex(Stream stream);

然后重新创建原始签名,如下所示;

private int WriteLogikParameterTyp(FileStream filestream)
{
     return WriteLogikParameterTyp_Ex(filestream);
}

Suggestion;

Rename the method like this

private int WriteLogikParameterTyp_Ex(Stream stream);

Then recreate the original signature like;

private int WriteLogikParameterTyp(FileStream filestream)
{
     return WriteLogikParameterTyp_Ex(filestream);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文