tags:

views:

196

answers:

3

I'm writing a class that needs to take in an object, record it's current state, update the object, and pass it to another class. The only problem is that you can only inherit from one class and I need that to inherit a class in my project. I'm interested in System.IO.Stream because I can if needed, move this class to it's own thread without most if not all of sockets and other methods of IPC. The main problem is, is there an interface for System.IO.Stream? If not, is there a way to get the functionality I want without sacrificing the project-critical data I depend on? (I'm sorry if I sound a little discoherent, I'm not really sure how to word this question.)


I am still very new to .NET,

+3  A: 

It sounds like IEnumerable<T> is a better fit - streams are good for passing bytes around, but iterators are good for representing more general streams of objects.

You'd want something that read from a stream (e.g. a socket) and created objects, probably with C# iterator blocks (yield statements etc). Then you can use processing functions, filters etc on the IEnumerable<T>, and blow it back into a socket (or other byte stream) later on.

To answer the question - no, Stream doesn't have an interface, but it's not clear how relevant that is to the threading part of your question. Is it that you're interested in async IO?

Jon Skeet
I'll play with IEnumerable<T> and report back. I think part of my problem is that I've been up for 48 hours and am dead tired.
Levi Campbell
After reading up on IEnumerable<T>, this will work much better. Thank you.
Levi Campbell
Good - but go to bed before trying it :)
Jon Skeet
+1  A: 

Why do you want an interface for Stream? implementing the interface won't give you any functionality from the class, it'll simply let other classes know that you provide that functionality. if your REALL REALLY need to have multiple inheritance (two base classes so that you can get the functionality from both), you could have your base class, the one you definately need, be a subclass of Stream itself.

public class MyObject : Base Object
{

}

public class BaseObject : Stream
{

}

etc..?

mroe background / context might help.

DNeoMatrix
A: 

It's really hard to figure out what you're trying to do here.

This sounds like a candidate for aggregation over inheritance. Instead of extending System.IO.Stream, Why don't you pass one into the object to use? This could be as a property or a get/set method, and if you pass the object off to another thread, the stream goes with it.

chris