Skip to content

Use reflection to discover cascading parameters in ComponentRenderer#75

Merged
justinyoo merged 4 commits intofeat/cacading-parametersfrom
copilot/sub-pr-74
Jan 2, 2026
Merged

Use reflection to discover cascading parameters in ComponentRenderer#75
justinyoo merged 4 commits intofeat/cacading-parametersfrom
copilot/sub-pr-74

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 2, 2026

Addresses feedback on #74 to remove hardcoded cascading parameter names that create tight coupling between ComponentRenderer and theme view base classes.

Changes

  • Replace hardcoded HashSet of parameter names with reflection-based discovery
  • Scan ScissorHands.Theme assembly at startup to detect properties with [CascadingParameter] attribute
  • Use lazy initialization to minimize reflection overhead to one-time cost
  • Add error handling for ReflectionTypeLoadException and use GetExportedTypes() for safety

Before

var cascadingKeys = new HashSet<string>(StringComparer.Ordinal)
{
    "Documents",
    "Document", 
    "Plugins",
    "Theme",
    "Site"
};

After

private static readonly Lazy<HashSet<string>> _cascadingParameterNames = new(() =>
{
    var parameterNames = new HashSet<string>(StringComparer.Ordinal);
    var themeAssembly = typeof(PageViewBase).Assembly;
    
    var allTypes = themeAssembly.GetExportedTypes();
    foreach (var type in allTypes)
    {
        var cascadingProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
            .Where(p => p.GetCustomAttribute<CascadingParameterAttribute>() is not null);
        
        foreach (var property in cascadingProperties)
            parameterNames.Add(property.Name);
    }
    
    return parameterNames;
});

New cascading parameters added to theme view base classes will be automatically discovered without requiring manual updates to the renderer.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 2, 2026 05:44
…detection

Co-authored-by: justinyoo <1538528+justinyoo@users.noreply.github.com>
…Theme assembly

Co-authored-by: justinyoo <1538528+justinyoo@users.noreply.github.com>
Co-authored-by: justinyoo <1538528+justinyoo@users.noreply.github.com>
Copilot AI changed the title [WIP] Update cascading parameters for theme views Use reflection to discover cascading parameters in ComponentRenderer Jan 2, 2026
Copilot AI requested a review from justinyoo January 2, 2026 05:54
@justinyoo justinyoo marked this pull request as ready for review January 2, 2026 05:57
@justinyoo justinyoo merged commit df7b1eb into feat/cacading-parameters Jan 2, 2026
@justinyoo justinyoo deleted the copilot/sub-pr-74 branch January 2, 2026 05:57
justinyoo added a commit that referenced this pull request Jan 2, 2026
* Update to cascading parameters

* Refactor StaticSiteGenerator

* Refactor ScissorHandsApplication to builder

* Add more tests

* Update README

* Update src/ScissorHands.Web/Generators/StaticSiteGenerator.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fix null-checking logic in IndexView.razor (#76)

* Initial plan

* Fix null-checking logic in IndexView.razor

Co-authored-by: justinyoo <1538528+justinyoo@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: justinyoo <1538528+justinyoo@users.noreply.github.com>

* Use reflection to discover cascading parameters in ComponentRenderer (#75)

* Initial plan

* Refactor ComponentRenderer to use reflection for cascading parameter detection

Co-authored-by: justinyoo <1538528+justinyoo@users.noreply.github.com>

* Improve reflection to auto-discover cascading parameters from entire Theme assembly

Co-authored-by: justinyoo <1538528+justinyoo@users.noreply.github.com>

* Add error handling and use GetExportedTypes for safer reflection

Co-authored-by: justinyoo <1538528+justinyoo@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: justinyoo <1538528+justinyoo@users.noreply.github.com>

* Improve reflection-based method invocation with caching and error handling (#77)

* Initial plan

* Add robust error handling and caching for reflection-based method invocation

Co-authored-by: justinyoo <1538528+justinyoo@users.noreply.github.com>

* Add thread-safety and improve exception handling

Co-authored-by: justinyoo <1538528+justinyoo@users.noreply.github.com>

* Address final code review feedback - constants and stack trace preservation

Co-authored-by: justinyoo <1538528+justinyoo@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: justinyoo <1538528+justinyoo@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: justinyoo <1538528+justinyoo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants