Reputation: 6435
I'm having trouble understanding how to use Observer.Using
I've got the following code
public void Test()
{
Observable.Using(
() => new GFSClientServiceClient(),
(c) => ObservableGetParameters(c))
.Subscribe(
(response) => Debug.Print("response"),
(ex) => Debug.Print("{0} error: {1}", Name, ex.Message),
() => Debug.Print("{0} complete", Name)
);
}
private static Func<IObservable<Dictionary<string, Dictionary<string, string>>>> ObservableGetParameters(GFSClientService.GFSClientServiceClient client)
{
return Observable.FromAsyncPattern<Dictionary<string, Dictionary<string, string>>>(client.BeginGetParameters, client.EndGetParameters);
}
I can't seem to get the using clause to work. It keeps telling me that the types cannot be inferred, but I don't see why? Anybody have any idea?
Upvotes: 1
Views: 1941
Reputation: 10650
EDIT:
My first answer was incorrect. Sorry about that. You probably want to do something like this:
public void Test()
{
Observable.Using(() => new Client(),
(c) => ObservableGetParameters(c))
.Subscribe((response) => Debug.Print("response"),
(ex) => Debug.Print("{0} error: {1}", "name", ex.Message),
() => Debug.Print("{0} complete", "name"));
}
private static IObservable<Dictionary<string, Dictionary<string, string>>> ObservableGetParameters(Client client)
{
return Observable.FromAsyncPattern<Dictionary<string, Dictionary<string, string>>>(client.BeginGetParameters, client.EndGetParameters)();
}
public class Client : IDisposable {
public IAsyncResult BeginGetParameters(AsyncCallback cb, object o) {
return default(IAsyncResult);
}
public Dictionary<string, Dictionary<string, string>> EndGetParameters(IAsyncResult res) {
return default(Dictionary<string, Dictionary<string, string>>);
}
public void Dispose() {}
}
Upvotes: 2