Skip to content

Commit

Permalink
Fixed review
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasherceg committed Nov 3, 2024
1 parent 2f3ced4 commit e09359d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Adapters/Tests/WebForms/HybridRouteLinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public async Task HybridRouteLink_SuffixAndQueryString()
}
}

class ControlTestViewModel
public class ControlTestViewModel
{
public int Value { get; set; } = 15;

Expand All @@ -90,7 +90,7 @@ class ControlTestViewModel
};
}

class ControlTestChildViewModel
public class ControlTestChildViewModel
{
public int Id { get; set; }
public string Name { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions src/Framework/Framework/Compilation/Binding/TypeRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -62,7 +62,7 @@ public TypeRegistry AddSymbols(IEnumerable<Func<string, Expression?>> 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<string, Expression> predefinedTypes =
Expand Down Expand Up @@ -129,7 +129,7 @@ public TypeRegistry AddImportedTypes(CompiledAssemblyCache compiledAssemblyCache
else return t => TypeRegistry.CreateStatic(compiledAssemblyCache.FindType(import.Namespace + "." + t));
}

class ExpressionTypeComparer : IEqualityComparer<Expression?>
class ExpressionTypeComparer : IEqualityComparer<Expression>
{
public static readonly ExpressionTypeComparer Instance = new();

Expand All @@ -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();
}
}
}
13 changes: 13 additions & 0 deletions src/Framework/Framework/Utils/ReflectionUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -778,5 +778,18 @@ internal static Type AssignGenericParameters(Type t, IReadOnlyDictionary<Type, T
return t;
}
}

/// <summary>
/// Determines whether the type is public and has the entire chain of nested parents public.
/// </summary>
public static bool IsPublicType(this Type type)
{
if (type.IsPublic) return true;
if (type.IsNested)
{
return type.IsNestedPublic && IsPublicType(type.DeclaringType!);
}
return false;
}
}
}

0 comments on commit e09359d

Please sign in to comment.