Skip to content

Commit 2b1d1b8

Browse files
committed
Fix support for .NET 3.5
1 parent 0e8ec32 commit 2b1d1b8

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

src/Proyecto26.RestClient/Helpers/ExecuteOnMainThread.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
#if NET_40
12
using System;
3+
using System.Collections;
24
using System.Collections.Concurrent;
5+
#endif
36
using UnityEngine;
47

58
namespace Proyecto26.Helper
@@ -18,6 +21,23 @@ namespace Proyecto26.Helper
1821
/// </example>
1922
public class ExecuteOnMainThread : MonoBehaviour
2023
{
24+
private static ExecuteOnMainThread _instance;
25+
public static ExecuteOnMainThread Instance { get { return _instance; } }
26+
27+
void Awake()
28+
{
29+
if (_instance != null && _instance != this)
30+
{
31+
Destroy(this.gameObject);
32+
}
33+
else
34+
{
35+
_instance = this;
36+
DontDestroyOnLoad(this.gameObject);
37+
}
38+
}
39+
40+
#if NET_40
2141
/// <summary>
2242
/// Store all instance of Action's and try to invoke them
2343
/// </summary>
@@ -30,11 +50,16 @@ void Update()
3050
{
3151
if (!RunOnMainThread.IsEmpty)
3252
{
33-
while (RunOnMainThread.TryDequeue(out var action))
53+
Action action;
54+
while (RunOnMainThread.TryDequeue(out action))
3455
{
35-
action?.Invoke();
56+
if (action != null) {
57+
action.Invoke();
58+
action = null;
59+
}
3660
}
3761
}
3862
}
63+
#endif
3964
}
4065
}

src/Proyecto26.RestClient/Helpers/HttpBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private static RequestException CreateException(RequestHelper options, UnityWebR
9898
return new RequestException(options, request.error, IsHttpError, IsNetworkError, request.responseCode, options.ParseResponseBody ? request.downloadHandler.text : "body not parsed");
9999
}
100100

101-
private static void DebugLog(bool debugEnabled, object message, bool isError)
101+
public static void DebugLog(bool debugEnabled, object message, bool isError)
102102
{
103103
if (debugEnabled)
104104
{

src/Proyecto26.RestClient/Helpers/RequestHelperExtension.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,17 @@ public bool DefaultContentType
121121
/// </summary>
122122
public void Abort()
123123
{
124-
if (this.Request != null && !this.IsAborted)
124+
if (!this.IsAborted && this.Request != null)
125125
{
126126
try
127127
{
128128
this.IsAborted = true;
129-
this.Request.Abort();
129+
if (!this.Request.isDone) {
130+
this.Request.Abort();
131+
}
132+
}
133+
catch (Exception error) {
134+
HttpBase.DebugLog(this.EnableDebug, error.Message, true);
130135
}
131136
finally
132137
{

src/Proyecto26.RestClient/RestClient.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,25 @@ public static partial class RestClient
1414
{
1515
#region Common
1616

17+
private static System.Version _version;
1718
/// <summary>
1819
/// Gets the version of the RestClient library.
1920
/// </summary>
2021
public static System.Version Version
2122
{
2223
get
2324
{
24-
return Version.Parse("2.6.2");
25+
if (_version == null) {
26+
_version = new System.Version("2.6.2");
27+
}
28+
return _version;
2529
}
2630
}
2731

32+
private static Dictionary<string, string> _defaultRequestParams;
2833
/// <summary>
2934
/// Default query string params.
3035
/// </summary>
31-
private static Dictionary<string, string> _defaultRequestParams;
3236
public static Dictionary<string, string> DefaultRequestParams
3337
{
3438
get

0 commit comments

Comments
 (0)