Skip to content

Commit

Permalink
Improve code in TypeExtensions and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skrysmanski committed May 6, 2024
1 parent 02b51fb commit 364cb41
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/AppMotor.Core/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public static bool Is(this Type typeToCheck, Type baseOrInterfaceType)
//
if (baseOrInterfaceType.IsInterface)
{
var baseTypeFullName = baseOrInterfaceType.FullName!;
var interfaceTypeFullName = baseOrInterfaceType.FullName!;

//
// Try "Type.GetInterface()" first, if possible.
Expand All @@ -326,7 +326,7 @@ public static bool Is(this Type typeToCheck, Type baseOrInterfaceType)
{
try
{
var implementedInterface = typeToCheck.GetInterface(baseTypeFullName);
var implementedInterface = typeToCheck.GetInterface(interfaceTypeFullName);
return implementedInterface?.Assembly == baseOrInterfaceType.Assembly;
}
catch (AmbiguousMatchException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,15 @@ public void Test_Is()
[Fact]
public void Test_Is_OpenGeneric()
{
// Non-nested types
typeof(List<string>).Is(typeof(IReadOnlyCollection<>)).ShouldBe(true);
typeof(List<>).Is(typeof(IReadOnlyCollection<>)).ShouldBe(true);
typeof(List<>).Is(typeof(IReadOnlyCollection<string>)).ShouldBe(false);
typeof(List<>).Is(typeof(object)).ShouldBe(true);
typeof(List<>).Is(typeof(int)).ShouldBe(false);
typeof(List<int>).Is(typeof(GenericClassA<>)).ShouldBe(false);

// Nested types
typeof(GenericClassB<int, string>).Is(typeof(IGenericTestInterface<>)).ShouldBe(true);
typeof(GenericClassB<int, string>).Is(typeof(GenericClassA<>)).ShouldBe(true);
typeof(GenericClassC<int, string>).Is(typeof(GenericClassA<>)).ShouldBe(true);
Expand Down

0 comments on commit 364cb41

Please sign in to comment.