Andre
Andre

Reputation: 3263

Use a MemoryStream with a function that expects a Filestream

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?

Upvotes: 1

Views: 1709

Answers (5)

Dead account
Dead account

Reputation: 19960

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);
}

Upvotes: 0

AnthonyWJones
AnthonyWJones

Reputation: 189457

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

Upvotes: 0

Mitch Wheat
Mitch Wheat

Reputation: 300549

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...

Upvotes: 0

Gishu
Gishu

Reputation: 136613

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.

Upvotes: 1

Dead account
Dead account

Reputation: 19960

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.

Upvotes: 1

Related Questions