Skip to content

Commit 2060e4d

Browse files
CopilotStefH
andcommitted
Change IsTypePubliclyAccessible parameter from Type to TypeInfo
Agent-Logs-Url: https://github.com/zzzprojects/System.Linq.Dynamic.Core/sessions/675543ad-d73e-4782-91c3-a63a7a0bab58 Co-authored-by: StefH <249938+StefH@users.noreply.github.com>
1 parent fb605bf commit 2060e4d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/System.Linq.Dynamic.Core/DynamicClassFactory.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ private static Type EmitType(IList<DynamicProperty> properties, bool createParam
293293
// Use object-based equality comparer for types that are not publicly accessible from
294294
// the dynamic assembly (e.g., compiler-generated anonymous types). Calling
295295
// EqualityComparer<T>.get_Default() for a non-public T will throw MethodAccessException.
296-
var fieldTypeIsAccessible = IsTypePubliclyAccessible(fieldType);
296+
var fieldTypeIsAccessible = IsTypePubliclyAccessible(fieldType.GetTypeInfo());
297297
var equalityType = fieldTypeIsAccessible ? fieldType : typeof(object);
298298
var equalityComparerT = EqualityComparer.MakeGenericType(equalityType);
299299

@@ -437,10 +437,10 @@ private static Type EmitType(IList<DynamicProperty> properties, bool createParam
437437
/// type arguments in EqualityComparer&lt;T&gt; from a dynamic assembly without causing
438438
/// a <see cref="MethodAccessException"/> at runtime.
439439
/// </summary>
440-
private static bool IsTypePubliclyAccessible(Type type)
440+
private static bool IsTypePubliclyAccessible(TypeInfo typeInfo)
441441
{
442442
// Check if the type itself is public
443-
if (!type.IsPublic && !type.IsNestedPublic)
443+
if (!typeInfo.IsPublic && !typeInfo.IsNestedPublic)
444444
{
445445
return false;
446446
}
@@ -449,9 +449,9 @@ private static bool IsTypePubliclyAccessible(Type type)
449449
// all type arguments must also be publicly accessible.
450450
// Generic type definitions (e.g., List<>) have unbound type parameters
451451
// which are not concrete types and should not be checked.
452-
if (type.IsGenericType && !type.IsGenericTypeDefinition)
452+
if (typeInfo.IsGenericType && !typeInfo.IsGenericTypeDefinition)
453453
{
454-
return type.GetGenericArguments().All(IsTypePubliclyAccessible);
454+
return typeInfo.GetGenericArguments().All(t => IsTypePubliclyAccessible(t.GetTypeInfo()));
455455
}
456456

457457
return true;

0 commit comments

Comments
 (0)