I want to use the .NET 4.0 interface IObserver for a library that needs to support previous versions of the framework as well. I already have conditional compilation which lets me build for each of the framework versions.
I don't want to use the Rx Extensions' version of IObserver<T>
as that would add an unnecessary dependency to an otherwise stand-alone assembly.
What I'm considering is adding this block of code to my library and my question to all of you is this:
1) I know this is a bad idea, but I'm trying to figure out exactly, "Why?"
#if !NET40
namespace System
{
public interface IObserver<in T>
{
void OnCompleted();
void OnError(Exception error);
void OnNext(T value);
}
}
#endif
I want to use the standard interface so that .NET 4.0 users can integrate in cool ways that I haven't even thought of yet. So I don't want to just duplicate the concept and loose the integration with other up and coming IObservable<T>
usages.
The dangers that I see are if the .NET 3.5 build of my library is used in .NET 4.0 there could be type collisions. Ideally though, someone using v4.0 would use the 4.0 build of the library.
Are there any other things that I should be aware of with this approach?
2) Alternatively, I've considered doing this in my code instead (which is the direction I'm leaning) and would like to know people's thoughts on why this is a bad idea:
#if !NET40
namespace Foo
{
public interface IObserverProxy<in T>
{
void OnCompleted();
void OnError(Exception error);
void OnNext(T value);
}
}
#endif
And later where I want to use it:
#if NET40
using IObserverBar=System.IObserver<Bar>;
#else
using IObserverBar=Foo.IObserverProxy<Bar>;
#endif
Any thoughts?