File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
src/CodeOfChaos.Extensions
tests/Tests.CodeOfChaos.Extensions Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ // ---------------------------------------------------------------------------------------------------------------------
2+ // Imports
3+ // ---------------------------------------------------------------------------------------------------------------------
4+ // ReSharper disable once CheckNamespace
5+ namespace System ;
6+
7+ // ---------------------------------------------------------------------------------------------------------------------
8+ // Code
9+ // ---------------------------------------------------------------------------------------------------------------------
10+ public static class TypeExtensions {
11+ public static bool MatchesGenericType ( this Type type , Type genericType ) {
12+ if ( ! type . IsGenericType ) return false ;
13+ return type . GetGenericTypeDefinition ( ) == genericType ;
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ // ---------------------------------------------------------------------------------------------------------------------
2+ // Imports
3+ // ---------------------------------------------------------------------------------------------------------------------
4+ namespace Tests . CodeOfChaos . Extensions ;
5+
6+ // ---------------------------------------------------------------------------------------------------------------------
7+ // Code
8+ // ---------------------------------------------------------------------------------------------------------------------
9+ public class TypeExtensionTests {
10+ [ Test ]
11+ public async Task MatchesGenericType_ShouldReturnTrue ( ) {
12+ // Arrange
13+ var type = typeof ( List < > ) ;
14+ var genericType = typeof ( List < > ) ;
15+
16+ // Act
17+ var result = type . MatchesGenericType ( genericType ) ;
18+
19+ // Assert
20+ await Assert . That ( result ) . IsTrue ( ) ;
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments