Skip to content

Issue: Nested if statement should be merged for clarity and readability #703

@ziagham

Description

@ziagham

What version of FlowSynx?

1.2.3

Describe the bug

There’s a redundant nested if statement that can be merged into a single conditional statement.
This simplifies the logic and improves readability without changing functionality.

File: src/FlowSynx.Infrastructure/PluginHost/Cache/PluginCacheService.cs
Methos: RegisterEvictionCallback

Current Implementation

private void RegisterEvictionCallback(MemoryCacheEntryOptions options)
{
    options.RegisterPostEvictionCallback((_, evictedValue, reason, _) =>
    {
        if (reason is EvictionReason.Expired or EvictionReason.Removed)
        {
            if (evictedValue is IPluginLoader pluginHandle)
            {
                pluginHandle.Unload();
            }
        }
    });
}

Proposed Fix

Merge the two if statements into one combined condition.

private void RegisterEvictionCallback(MemoryCacheEntryOptions options)
{
    options.RegisterPostEvictionCallback((_, evictedValue, reason, _) =>
    {
        if ((reason is EvictionReason.Expired or EvictionReason.Removed) &&
            evictedValue is IPluginLoader pluginHandle)
        {
            pluginHandle.Unload();
        }
    });
}

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions