将 MemoryStream 与需要 Filestream 的函数一起使用
我这里有一些函数,例如,它们被定义为
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不,
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.
由于您无法更改函数签名以接受更通用的类型。我建议写入临时文件,然后将内容读入 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.
否。
如果您无权访问它们,您可以使用 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...
不可以。FileStream 不公开可调用的构造函数,因此您无法继承它来模拟它。
No. FileStream doesn't expose a constructor that can be called so you can't inherit from it in order to emulate it.
建议;
像这样重命名该方法
然后重新创建原始签名,如下所示;
Suggestion;
Rename the method like this
Then recreate the original signature like;