I'm assuming you control the Foo class, since you're talking about adding an event to it as one option. Since you own the class, is there any reason you can't define your own IObservable implementation for the Do method?
public class Foo
{
DoObservable _doValues = new DoObservable();
public IObservable<String> DoValues
{
return _doValues;
}
public string Do(int param)
{
string result;
// whatever
_doValues.Notify(result);
}
}
public class DoObservable : IObservable<String>
{
List<IObserver<String>> _observers = new List<IObserver<String>>();
public void Notify(string s)
{
foreach (var obs in _observers) obs.OnNext(s);
}
public IObserver<String> Subscribe(IObserver<String> observer)
{
_observers.Add(observer);
return observer;
}
}
Your class now has an Observable<String>
property which provides a way to subscribe to the values returned from the Do method:
public class StringWriter : IObserver<String>
{
public void OnNext(string value)
{
Console.WriteLine("Do returned " + value);
}
// and the other IObserver<String> methods
}
var subscriber = myFooInstance.DoValues.Subscribe(new StringWriter());
// from now on, anytime myFooInstance.Do() is called, the value it
// returns will be written to the console by the StringWriter observer.
I've not dabbled too much into the reactive framework, but I think this is close to how you would do this.