Skip to content

Commit e09359d

Browse files
committed
Fixed review
1 parent 2f3ced4 commit e09359d

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

src/Adapters/Tests/WebForms/HybridRouteLinkTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public async Task HybridRouteLink_SuffixAndQueryString()
7878
}
7979
}
8080

81-
class ControlTestViewModel
81+
public class ControlTestViewModel
8282
{
8383
public int Value { get; set; } = 15;
8484

@@ -90,7 +90,7 @@ class ControlTestViewModel
9090
};
9191
}
9292

93-
class ControlTestChildViewModel
93+
public class ControlTestChildViewModel
9494
{
9595
public int Id { get; set; }
9696
public string Name { get; set; }

src/Framework/Framework/Compilation/Binding/TypeRegistry.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public TypeRegistry(CompiledAssemblyCache compiledAssemblyCache, ImmutableDictio
3535
{
3636
return expr;
3737
}
38-
var matchedExpressions = resolvers.Select(r => r(name)).Where(e => e != null).Distinct(ExpressionTypeComparer.Instance).ToList();
38+
var matchedExpressions = resolvers.Select(r => r(name)).WhereNotNull().Distinct(ExpressionTypeComparer.Instance).ToList();
3939
if (matchedExpressions.Count > 1)
4040
{
4141
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<Func<string, Expression?>> symbols)
6262
[return: NotNullIfNotNull("type")]
6363
public static Expression? CreateStatic(Type? type)
6464
{
65-
return type is { IsPublic: true } or { IsNestedPublic: true } ? new StaticClassIdentifierExpression(type) : null;
65+
return type?.IsPublicType() == true ? new StaticClassIdentifierExpression(type) : null;
6666
}
6767

6868
private static readonly ImmutableDictionary<string, Expression> predefinedTypes =
@@ -129,7 +129,7 @@ public TypeRegistry AddImportedTypes(CompiledAssemblyCache compiledAssemblyCache
129129
else return t => TypeRegistry.CreateStatic(compiledAssemblyCache.FindType(import.Namespace + "." + t));
130130
}
131131

132-
class ExpressionTypeComparer : IEqualityComparer<Expression?>
132+
class ExpressionTypeComparer : IEqualityComparer<Expression>
133133
{
134134
public static readonly ExpressionTypeComparer Instance = new();
135135

@@ -141,7 +141,7 @@ public bool Equals(Expression? x, Expression? y)
141141
return ReferenceEquals(x.Type, y.Type);
142142
}
143143

144-
public int GetHashCode(Expression? obj) => obj?.Type.GetHashCode() ?? 0;
144+
public int GetHashCode(Expression obj) => obj.Type.GetHashCode();
145145
}
146146
}
147147
}

src/Framework/Framework/Utils/ReflectionUtils.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,5 +778,18 @@ internal static Type AssignGenericParameters(Type t, IReadOnlyDictionary<Type, T
778778
return t;
779779
}
780780
}
781+
782+
/// <summary>
783+
/// Determines whether the type is public and has the entire chain of nested parents public.
784+
/// </summary>
785+
public static bool IsPublicType(this Type type)
786+
{
787+
if (type.IsPublic) return true;
788+
if (type.IsNested)
789+
{
790+
return type.IsNestedPublic && IsPublicType(type.DeclaringType!);
791+
}
792+
return false;
793+
}
781794
}
782795
}

0 commit comments

Comments
 (0)