RemoteAgents Mono GTK Linux: Receiving null when nothing useful arrived.
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Sat, 22 Feb 2014 16:28:02 +0000 (17:28 +0100)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Sat, 22 Feb 2014 16:28:02 +0000 (17:28 +0100)
default(TResult)

Specifies the default value of the type parameter.
This will be null for reference types and zero for value types.

Mono/RemoteAgents/GTKLinux/MainWindow.cs
Mono/RemoteAgents/GTKLinux/Model/CallRemoteProcedure.cs

index 22371ca..7fb8be7 100644 (file)
@@ -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;
+            }
         }
     }
 }
index 27572ea..f67879c 100644 (file)
@@ -16,8 +16,7 @@ namespace Example.RemoteAgents.GTKLinux.Model
 
     async public Task<TResult> callRemoteService<TResult>(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<byte[]> responseBytes = response.Content.ReadAsByteArrayAsync();
         string responseString = System.Text.Encoding.UTF8.GetString(responseBytes.Result);