© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
9 replies
SWEETPONY

✅ strange behavior with dictionary keys

I have following code:
public class UISchemaGenerator
{
    private record CacheKey(
        Either<CustomFieldSet, CustomField.CustomField> Type,
        CultureInfo Culture);

    private readonly ConcurrentDictionary<CacheKey, UISchemaSpecification> _cache = new();

    public UISchemaSpecification Generate(
        Either<CustomFieldSet, CustomField.CustomField> eitherField,
        MandatorySecurityScope scope = default,
        CultureInfo culture = default)
    {
        culture ??= CultureInfo.CurrentCulture;

        return eitherField.Match(
            ifA: cfs => _cache.GetOrAdd(
                new CacheKey(cfs, culture),
                _ => InternalGenerator(cfs, scope, culture)),
            ifB: cf => _cache.GetOrAdd(
                new CacheKey(cf, culture),
                _ => InternalGenerator(cf, culture)));
    }
public class UISchemaGenerator
{
    private record CacheKey(
        Either<CustomFieldSet, CustomField.CustomField> Type,
        CultureInfo Culture);

    private readonly ConcurrentDictionary<CacheKey, UISchemaSpecification> _cache = new();

    public UISchemaSpecification Generate(
        Either<CustomFieldSet, CustomField.CustomField> eitherField,
        MandatorySecurityScope scope = default,
        CultureInfo culture = default)
    {
        culture ??= CultureInfo.CurrentCulture;

        return eitherField.Match(
            ifA: cfs => _cache.GetOrAdd(
                new CacheKey(cfs, culture),
                _ => InternalGenerator(cfs, scope, culture)),
            ifB: cf => _cache.GetOrAdd(
                new CacheKey(cf, culture),
                _ => InternalGenerator(cf, culture)));
    }


CustomField.CustomField is object with some properties
problem: if value of one of the properties will change I will not call InternalGenerator, I will use old value from cache but actually property value has changed
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Need help with strange .NET MAUI Entry Display Behavior
C#CC# / help
2y ago
❔ Problem with Dictionary<ulong, Image> (Strange work of memory access)
C#CC# / help
3y ago
Dictionary<> Keys do not get fetched properly
C#CC# / help
16mo ago