From: gu.martinm@gmail.com Date: Sat, 22 Feb 2014 16:28:02 +0000 (+0100) Subject: RemoteAgents Mono GTK Linux: Receiving null when nothing useful arrived. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=cd89c107945467684cbeaf4a656e96b2bffd1764;p=CSharpForFun%2F.git RemoteAgents Mono GTK Linux: Receiving null when nothing useful arrived. default(TResult) Specifies the default value of the type parameter. This will be null for reference types and zero for value types. --- diff --git a/Mono/RemoteAgents/GTKLinux/MainWindow.cs b/Mono/RemoteAgents/GTKLinux/MainWindow.cs index 22371ca..7fb8be7 100644 --- a/Mono/RemoteAgents/GTKLinux/MainWindow.cs +++ b/Mono/RemoteAgents/GTKLinux/MainWindow.cs @@ -34,7 +34,11 @@ namespace Example.RemoteAgents.GTKLinux async private void ButtonGetDateClicked(object sender, EventArgs a) { - this.RemoteDate.Buffer.Text = await view.getCurrentDate(); + string currentDate = await view.getCurrentDate(); + if (currentDate != null) + { + this.RemoteDate.Buffer.Text = currentDate; + } } } } diff --git a/Mono/RemoteAgents/GTKLinux/Model/CallRemoteProcedure.cs b/Mono/RemoteAgents/GTKLinux/Model/CallRemoteProcedure.cs index 27572ea..f67879c 100644 --- a/Mono/RemoteAgents/GTKLinux/Model/CallRemoteProcedure.cs +++ b/Mono/RemoteAgents/GTKLinux/Model/CallRemoteProcedure.cs @@ -16,8 +16,7 @@ namespace Example.RemoteAgents.GTKLinux.Model async public Task callRemoteService(string uri, string method) { - TResult result = default(TResult); - POST postData = new POST(); + var postData = new POST(); postData.Id = "2114567586433855105"; postData.JSONrpc = "2.0"; postData.Method = method; @@ -27,6 +26,8 @@ namespace Example.RemoteAgents.GTKLinux.Model HttpResponseMessage response = await this.issueCall(uri, content); + TResult result = default(TResult); + if (response.StatusCode == HttpStatusCode.OK) { Task responseBytes = response.Content.ReadAsByteArrayAsync(); string responseString = System.Text.Encoding.UTF8.GetString(responseBytes.Result);