• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

KeRNeLith / ImmediateReflection / 301

01 Oct 2025 07:29PM UTC coverage: 99.099% (-0.6%) from 99.738%
301

push

appveyor

KeRNeLith
Add a custom hashcode implementation on PropertyInfo usage as key for .NET targets as there is a regression on them.

See https://github.com/dotnet/runtime/issues/114280.

770 of 777 relevant lines covered (99.1%)

250.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/src/ImmediateReflection/Cache/MemoryCache.cs
1
using System;
2
using System.Collections;
3
using System.Diagnostics;
4
using JetBrains.Annotations;
5

6
namespace ImmediateReflection
7
{
8
    /// <summary>
9
    /// Represents a type that implements a memory cache.
10
    /// </summary>
11
    /// <typeparam name="TKey">Cache key type.</typeparam>
12
    /// <typeparam name="TValue">Cache value type.</typeparam>
13
    internal sealed class MemoryCache<TKey, TValue>
14
        where TValue : class
15
    {
16
        [NotNull]
17
        private readonly Hashtable _cache;
18

19
        public MemoryCache(IEqualityComparer comparer = null)
6✔
20
        {
21
            _cache = new Hashtable(comparer);
6✔
22
        }
6✔
23

24
        /// <summary>
25
        /// Gets the cached value corresponding to the given <paramref name="key"/> if already cached, or creates
26
        /// a new entry if not available.
27
        /// </summary>
28
        /// <param name="key">Cache key.</param>
29
        /// <param name="valueFactory">Factory method to create the value if it does not exist.</param>
30
        /// <returns>The value.</returns>
31
        [NotNull]
32
        [ContractAnnotation("key:null => halt;valueFactory:null => halt")]
33
        public TValue GetOrCreate([NotNull] TKey key, [NotNull, InstantHandle] Func<TValue> valueFactory)
34
        {
35
            Debug.Assert(key != null);
36
            Debug.Assert(valueFactory != null);
37

38
            // ReSharper disable once InconsistentlySynchronizedField, Justification: HashTable is thread safe for reading
39
            var cachedValue = (TValue)_cache[key];
6,097✔
40
            if (cachedValue != null)
6,097✔
41
                return cachedValue;
5,171✔
42

43
            lock (_cache)
926✔
44
            {
45
                // Double check (init during lock wait)
46
                cachedValue = (TValue)_cache[key];
926✔
47
                if (cachedValue != null)
926✔
48
                    return cachedValue;
×
49

50
                cachedValue = valueFactory();
926✔
51
                _cache[key] = cachedValue;
926✔
52
                return cachedValue;
926✔
53
            }
54
        }
926✔
55
    }
56
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc