Skip to content

Conversation

@AlisherAmonulloev
Copy link

@AlisherAmonulloev AlisherAmonulloev commented Nov 7, 2025

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modifies the DynamicClassBridge class to dynamically retrieve the indexer name from the System.Linq.Dynamic.Core.DynamicClass type instead of hardcoding it as "Item". This change makes the code more flexible and adaptable to potential variations in the DynamicClass implementation.

Key Changes

  • Replaced hardcoded indexer method lookup with dynamic retrieval based on a static field
  • Added reflection logic to read the IndexerName field from the DynamicClass type
  • Included fallback to "Item" if the field is not found or null

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


var indexerNameField = CLASS_TYPE.GetField("IndexerName", BindingFlags.NonPublic | BindingFlags.Static);
var indexerName = indexerNameField?.GetValue(null) as string ?? "Item";
INDEXER_METHOD = CLASS_TYPE.GetMethod("get_" + indexerName);
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GetMethod call on line 29 can return null if the method is not found. This would leave INDEXER_METHOD as null, causing a NullReferenceException when GetMember is invoked later (line 43). Consider adding null-checking and throwing a descriptive exception if the method cannot be found, similar to how other reflection calls are handled in this constructor.

Suggested change
INDEXER_METHOD = CLASS_TYPE.GetMethod("get_" + indexerName);
INDEXER_METHOD = CLASS_TYPE.GetMethod("get_" + indexerName);
if (INDEXER_METHOD == null)
throw new Exception($"Could not find indexer method 'get_{indexerName}' on type '{CLASS_TYPE.FullName}'.");

Copilot uses AI. Check for mistakes.
@mpreyskurantov mpreyskurantov added dependencies Pull requests that update a dependency file .NET Pull requests that update .net code labels Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file .NET Pull requests that update .net code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants