From a02c1e05d53c69a17f076b09be59aa0b4e554635 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Mon, 17 Aug 2020 18:23:30 -0500 Subject: [PATCH] Adjusted references in BSIPA-Meta.csproj --- BSIPA-Meta/BSIPA-Meta.csproj | 24 +++++----- Net3-Proxy/CompilerServices.cs | 82 +++++++++++++++++----------------- 2 files changed, 54 insertions(+), 52 deletions(-) diff --git a/BSIPA-Meta/BSIPA-Meta.csproj b/BSIPA-Meta/BSIPA-Meta.csproj index b1404e5a..b91fbb9b 100644 --- a/BSIPA-Meta/BSIPA-Meta.csproj +++ b/BSIPA-Meta/BSIPA-Meta.csproj @@ -31,25 +31,27 @@ - - - - + + + Configuration=$(NoVerboseConfig) + Platform=AnyCPU + + + Configuration=$(NoVerboseConfig) + Platform=AnyCPU + + + Configuration=$(ProxyConfig) + Platform=$(ProxyPlatform) + - - - - - - - diff --git a/Net3-Proxy/CompilerServices.cs b/Net3-Proxy/CompilerServices.cs index 5ef760f5..d721f4b3 100644 --- a/Net3-Proxy/CompilerServices.cs +++ b/Net3-Proxy/CompilerServices.cs @@ -1,15 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace System.Runtime.CompilerServices -{ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace System.Runtime.CompilerServices +{ public sealed class ConditionalWeakTable where TKey : class where TValue : class - { - private readonly Dictionary, TValue> items = new Dictionary, TValue>(); - private readonly object _lock = new object(); - + { + private readonly Dictionary, TValue> items = new Dictionary, TValue>(); + private readonly object _lock = new object(); + private sealed class KeyComparer : IEqualityComparer> { public bool Equals(WeakReference x, WeakReference y) @@ -17,11 +17,11 @@ namespace System.Runtime.CompilerServices public int GetHashCode(WeakReference obj) => obj.TryGetTarget(out var key) ? key.GetHashCode() : 0; - } - - private static WeakReference WeakRef(TKey key) - => new WeakReference(key); - + } + + private static WeakReference WeakRef(TKey key) + => new WeakReference(key); + private sealed class GCTracker { public static event Action OnGC; @@ -32,11 +32,11 @@ namespace System.Runtime.CompilerServices if (!AppDomain.CurrentDomain.IsFinalizingForUnload() && !Environment.HasShutdownStarted) tracker.SetTarget(new GCTracker()); } - } - + } + public void Add(TKey key, TValue value) - { - if (key == null) + { + if (key == null) throw new ArgumentException("Null key", nameof(key)); lock (_lock) items.Add(WeakRef(key), value); @@ -52,8 +52,8 @@ namespace System.Runtime.CompilerServices return items.TryGetValue(WeakRef(key), out value); } - public delegate TValue CreateValueCallback(TKey key); - + public delegate TValue CreateValueCallback(TKey key); + public TValue GetValue(TKey key, CreateValueCallback createValueCallback) { if (createValueCallback == null) @@ -70,29 +70,29 @@ namespace System.Runtime.CompilerServices return value; } } - } - - public TValue GetOrCreateValue(TKey key) - => GetValue(key, k => Activator.CreateInstance()); - + } + + public TValue GetOrCreateValue(TKey key) + => GetValue(key, k => Activator.CreateInstance()); + public bool Remove(TKey key) - { - if (key == null) - throw new ArgumentException("Null key", nameof(key)); - + { + if (key == null) + throw new ArgumentException("Null key", nameof(key)); + return items.Remove(WeakRef(key)); - } - - public ConditionalWeakTable() - => GCTracker.OnGC += OnGC; - ~ConditionalWeakTable() - => GCTracker.OnGC -= OnGC; - + } + + public ConditionalWeakTable() + => GCTracker.OnGC += OnGC; + ~ConditionalWeakTable() + => GCTracker.OnGC -= OnGC; + private void OnGC() { // on each GC, we want to clear the entire set of empty keys var nullWeakRef = WeakRef(null); while (items.Remove(nullWeakRef)) ; // just loop - } - } -} + } + } +}