views:

811

answers:

5

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?

+1  A: 

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.

Dead account
That was just an example. That one is private and others are public. And there are a lot of them.
Andre
+1  A: 

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.

Gishu
Apologies; I beat you to the tempory file solution. We must have hit 'submit' at the same time :)
Dead account
A: 

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

Mitch Wheat
"Whether this is legal" - I'm sure nobody would arrest him :)
configurator
A: 

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

AnthonyWJones
A: 

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);
}
Dead account
Why not simply change the method signature? It would not break existing using code since FileStream is derived from Stream...
configurator
I'm assuming since he "can't change the method" he can't make it delegate either:). May the fastest finger win! :)
Gishu