|
@ -5,10 +5,11 @@ using System.Linq; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using Mono.Cecil; |
|
|
using Mono.Cecil; |
|
|
using System.Runtime.CompilerServices; |
|
|
using System.Runtime.CompilerServices; |
|
|
|
|
|
using System.Threading; |
|
|
#if NET3
|
|
|
#if NET3
|
|
|
using File = Net3_Proxy.File; |
|
|
using File = Net3_Proxy.File; |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace IPA.Utilities |
|
|
namespace IPA.Utilities |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
@ -143,7 +144,7 @@ namespace IPA.Utilities |
|
|
/// <value><see langword="true"/> if you can use <see cref="DateTime.Now"/> safely, <see langword="false"/> otherwise</value>
|
|
|
/// <value><see langword="true"/> if you can use <see cref="DateTime.Now"/> safely, <see langword="false"/> otherwise</value>
|
|
|
public static bool CanUseDateTimeNowSafely { get; private set; } = true; |
|
|
public static bool CanUseDateTimeNowSafely { get; private set; } = true; |
|
|
private static bool DateTimeSafetyUnknown = true; |
|
|
private static bool DateTimeSafetyUnknown = true; |
|
|
private static ulong UnsafeAdvanceTicks = 1; |
|
|
|
|
|
|
|
|
private static long UnsafeAdvanceTicks = 1; |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets the current <see cref="DateTime"/> if supported, otherwise, if Mono would throw a fit,
|
|
|
/// Gets the current <see cref="DateTime"/> if supported, otherwise, if Mono would throw a fit,
|
|
@ -170,7 +171,7 @@ namespace IPA.Utilities |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
if (CanUseDateTimeNowSafely) return DateTime.Now; |
|
|
if (CanUseDateTimeNowSafely) return DateTime.Now; |
|
|
else return DateTime.MinValue.AddTicks((long)UnsafeAdvanceTicks++); // return MinValue as a fallback
|
|
|
|
|
|
|
|
|
else return DateTime.MinValue.AddTicks(Interlocked.Increment(ref UnsafeAdvanceTicks)); // return MinValue as a fallback
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -190,8 +191,8 @@ namespace IPA.Utilities |
|
|
return cmpVal; |
|
|
return cmpVal; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// An object used to manage scope guards.
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// An object used to manage scope guards.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <example>
|
|
|
/// <example>
|
|
|
/// <code>
|
|
|
/// <code>
|
|
@ -199,12 +200,12 @@ namespace IPA.Utilities |
|
|
/// </code>
|
|
|
/// </code>
|
|
|
/// </example>
|
|
|
/// </example>
|
|
|
/// <seealso cref="ScopeGuard(Action)"/>
|
|
|
/// <seealso cref="ScopeGuard(Action)"/>
|
|
|
public struct ScopeGuardObject : IDisposable |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
public struct ScopeGuardObject : IDisposable |
|
|
|
|
|
{ |
|
|
private readonly Action action; |
|
|
private readonly Action action; |
|
|
/// <summary>
|
|
|
|
|
|
/// Creates a new scope guard that will invoke <paramref name="action"/> when disposed.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Creates a new scope guard that will invoke <paramref name="action"/> when disposed.
|
|
|
|
|
|
/// </summary>
|
|
|
/// <param name="action">the action to run on dispose</param>
|
|
|
/// <param name="action">the action to run on dispose</param>
|
|
|
public ScopeGuardObject(Action action) |
|
|
public ScopeGuardObject(Action action) |
|
|
=> this.action = action; |
|
|
=> this.action = action; |
|
@ -212,10 +213,10 @@ namespace IPA.Utilities |
|
|
=> action?.Invoke(); |
|
|
=> action?.Invoke(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Creates a scope guard for a given <see cref="Action"/>.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="action">the <see cref="Action"/> to run on dispose</param>
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Creates a scope guard for a given <see cref="Action"/>.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="action">the <see cref="Action"/> to run on dispose</param>
|
|
|
/// <returns>a <see cref="ScopeGuardObject"/> that will run <paramref name="action"/> on disposal</returns>
|
|
|
/// <returns>a <see cref="ScopeGuardObject"/> that will run <paramref name="action"/> on disposal</returns>
|
|
|
/// <example>
|
|
|
/// <example>
|
|
|
/// <code>
|
|
|
/// <code>
|
|
|