diff --git a/src/Adapters/Tests/WebForms/HybridRouteLinkTests.cs b/src/Adapters/Tests/WebForms/HybridRouteLinkTests.cs index fe3cc1616d..fa368198c0 100644 --- a/src/Adapters/Tests/WebForms/HybridRouteLinkTests.cs +++ b/src/Adapters/Tests/WebForms/HybridRouteLinkTests.cs @@ -78,7 +78,7 @@ public async Task HybridRouteLink_SuffixAndQueryString() } } - class ControlTestViewModel + public class ControlTestViewModel { public int Value { get; set; } = 15; @@ -90,7 +90,7 @@ class ControlTestViewModel }; } - class ControlTestChildViewModel + public class ControlTestChildViewModel { public int Id { get; set; } public string Name { get; set; } diff --git a/src/Framework/Framework/Compilation/Binding/TypeRegistry.cs b/src/Framework/Framework/Compilation/Binding/TypeRegistry.cs index 50c28b67fc..55d154a2cf 100644 --- a/src/Framework/Framework/Compilation/Binding/TypeRegistry.cs +++ b/src/Framework/Framework/Compilation/Binding/TypeRegistry.cs @@ -35,7 +35,7 @@ public TypeRegistry(CompiledAssemblyCache compiledAssemblyCache, ImmutableDictio { return expr; } - var matchedExpressions = resolvers.Select(r => r(name)).Where(e => e != null).Distinct(ExpressionTypeComparer.Instance).ToList(); + var matchedExpressions = resolvers.Select(r => r(name)).WhereNotNull().Distinct(ExpressionTypeComparer.Instance).ToList(); if (matchedExpressions.Count > 1) { throw new InvalidOperationException($"The identifier '{name}' is ambiguous between the following types: {string.Join(", ", matchedExpressions.Select(e => e!.Type.ToCode()))}. Please specify the namespace explicitly."); @@ -62,7 +62,7 @@ public TypeRegistry AddSymbols(IEnumerable> symbols) [return: NotNullIfNotNull("type")] public static Expression? CreateStatic(Type? type) { - return type is { IsPublic: true } or { IsNestedPublic: true } ? new StaticClassIdentifierExpression(type) : null; + return type?.IsPublicType() == true ? new StaticClassIdentifierExpression(type) : null; } private static readonly ImmutableDictionary predefinedTypes = @@ -129,7 +129,7 @@ public TypeRegistry AddImportedTypes(CompiledAssemblyCache compiledAssemblyCache else return t => TypeRegistry.CreateStatic(compiledAssemblyCache.FindType(import.Namespace + "." + t)); } - class ExpressionTypeComparer : IEqualityComparer + class ExpressionTypeComparer : IEqualityComparer { public static readonly ExpressionTypeComparer Instance = new(); @@ -141,7 +141,7 @@ public bool Equals(Expression? x, Expression? y) return ReferenceEquals(x.Type, y.Type); } - public int GetHashCode(Expression? obj) => obj?.Type.GetHashCode() ?? 0; + public int GetHashCode(Expression obj) => obj.Type.GetHashCode(); } } } diff --git a/src/Framework/Framework/Utils/ReflectionUtils.cs b/src/Framework/Framework/Utils/ReflectionUtils.cs index 91d6c2aa00..3eaf1ebe5f 100644 --- a/src/Framework/Framework/Utils/ReflectionUtils.cs +++ b/src/Framework/Framework/Utils/ReflectionUtils.cs @@ -778,5 +778,18 @@ internal static Type AssignGenericParameters(Type t, IReadOnlyDictionary + /// Determines whether the type is public and has the entire chain of nested parents public. + /// + public static bool IsPublicType(this Type type) + { + if (type.IsPublic) return true; + if (type.IsNested) + { + return type.IsNestedPublic && IsPublicType(type.DeclaringType!); + } + return false; + } } }