Skip to content

Commit

Permalink
Fix support for .NET 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
jdnichollsc committed Dec 13, 2021
1 parent 0e8ec32 commit 2b1d1b8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
29 changes: 27 additions & 2 deletions src/Proyecto26.RestClient/Helpers/ExecuteOnMainThread.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#if NET_40
using System;
using System.Collections;
using System.Collections.Concurrent;
#endif
using UnityEngine;

namespace Proyecto26.Helper
Expand All @@ -18,6 +21,23 @@ namespace Proyecto26.Helper
/// </example>
public class ExecuteOnMainThread : MonoBehaviour
{
private static ExecuteOnMainThread _instance;
public static ExecuteOnMainThread Instance { get { return _instance; } }

void Awake()
{
if (_instance != null && _instance != this)
{
Destroy(this.gameObject);
}
else
{
_instance = this;
DontDestroyOnLoad(this.gameObject);
}
}

#if NET_40
/// <summary>
/// Store all instance of Action's and try to invoke them
/// </summary>
Expand All @@ -30,11 +50,16 @@ void Update()
{
if (!RunOnMainThread.IsEmpty)
{
while (RunOnMainThread.TryDequeue(out var action))
Action action;
while (RunOnMainThread.TryDequeue(out action))
{
action?.Invoke();
if (action != null) {
action.Invoke();
action = null;
}
}
}
}
#endif
}
}
2 changes: 1 addition & 1 deletion src/Proyecto26.RestClient/Helpers/HttpBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static RequestException CreateException(RequestHelper options, UnityWebR
return new RequestException(options, request.error, IsHttpError, IsNetworkError, request.responseCode, options.ParseResponseBody ? request.downloadHandler.text : "body not parsed");
}

private static void DebugLog(bool debugEnabled, object message, bool isError)
public static void DebugLog(bool debugEnabled, object message, bool isError)
{
if (debugEnabled)
{
Expand Down
9 changes: 7 additions & 2 deletions src/Proyecto26.RestClient/Helpers/RequestHelperExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,17 @@ public bool DefaultContentType
/// </summary>
public void Abort()
{
if (this.Request != null && !this.IsAborted)
if (!this.IsAborted && this.Request != null)
{
try
{
this.IsAborted = true;
this.Request.Abort();
if (!this.Request.isDone) {
this.Request.Abort();
}
}
catch (Exception error) {
HttpBase.DebugLog(this.EnableDebug, error.Message, true);
}
finally
{
Expand Down
8 changes: 6 additions & 2 deletions src/Proyecto26.RestClient/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@ public static partial class RestClient
{
#region Common

private static System.Version _version;
/// <summary>
/// Gets the version of the RestClient library.
/// </summary>
public static System.Version Version
{
get
{
return Version.Parse("2.6.2");
if (_version == null) {
_version = new System.Version("2.6.2");
}
return _version;
}
}

private static Dictionary<string, string> _defaultRequestParams;
/// <summary>
/// Default query string params.
/// </summary>
private static Dictionary<string, string> _defaultRequestParams;
public static Dictionary<string, string> DefaultRequestParams
{
get
Expand Down

0 comments on commit 2b1d1b8

Please sign in to comment.