Skip to content

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

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

Improve reflection-based method invocation with caching and error handling#77
justinyoo merged 4 commits intofeat/cacading-parametersfrom
copilot/sub-pr-74-another-one

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 2, 2026

Addresses feedback on reflection-based method invocation in BuildSiteAsync that could fail at runtime with unclear errors and had performance overhead.

Performance

  • Cache MethodInfo after first lookup using thread-safe double-checked locking
  • Prevents repeated reflection queries on each build operation

Error Handling

  • Extract method discovery into GetBuildAsyncMethod() with explicit validation:
    • No BuildAsync method found
    • Wrong signature (expected 5 generic params, 3 method params)
    • Multiple overloads (ambiguous)
  • Preserve stack traces on TargetInvocationException using ExceptionDispatchInfo
  • Wrap reflection failures with actionable error messages

Before:

var buildMethod = _generator!.GetType()
    .GetMethods()
    .Single(m => /* inline predicate */);
var task = (Task?)buildMethod.MakeGenericMethod(...).Invoke(...);
return task ?? Task.CompletedTask;

After:

if (_cachedBuildMethod == null)
{
    lock (_cacheLock)
    {
        if (_cachedBuildMethod == null)
        {
            _cachedBuildMethod = GetBuildAsyncMethod();
        }
    }
}
var closedMethod = _cachedBuildMethod.MakeGenericMethod(...);
// + comprehensive exception handling

💡 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:43
…ocation

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

Co-authored-by: justinyoo <1538528+justinyoo@users.noreply.github.com>
Copilot AI changed the title [WIP] Update cascading parameters for theme views based on feedback Improve reflection-based method invocation with caching and error handling Jan 2, 2026
Copilot AI requested a review from justinyoo January 2, 2026 05:53
@justinyoo justinyoo marked this pull request as ready for review January 2, 2026 06:03
@justinyoo justinyoo merged commit 225d085 into feat/cacading-parameters Jan 2, 2026
@justinyoo justinyoo deleted the copilot/sub-pr-74-another-one branch January 2, 2026 06:03
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