File tree Expand file tree Collapse file tree 7 files changed +38
-5
lines changed
NetArchTest.Rules.UnitTests
NetArchTest.TestStructure Expand file tree Collapse file tree 7 files changed +38
-5
lines changed Original file line number Diff line number Diff line change @@ -10,9 +10,26 @@ static internal class PropertyDefinitionExtensions
1010 /// <returns>An indication of whether the property is readonly.</returns>
1111 public static bool IsReadonly ( this PropertyDefinition propertyDefinition )
1212 {
13- return propertyDefinition . SetMethod == null ;
13+ if ( propertyDefinition . SetMethod == null )
14+ {
15+ return true ;
16+ }
17+ else
18+ {
19+ if ( propertyDefinition . IsInitOnly ( ) )
20+ {
21+ return true ;
22+ }
23+ }
24+
25+ return false ;
1426 }
15-
27+
28+ public static bool IsInitOnly ( this PropertyDefinition propertyDefinition )
29+ {
30+ return propertyDefinition . SetMethod ? . ReturnType . FullName == "System.Void modreq(System.Runtime.CompilerServices.IsExternalInit)" ;
31+ }
32+
1633 /// <summary>
1734 /// Tests whether a property is nullable
1835 /// </summary>
Original file line number Diff line number Diff line change 2121 </PropertyGroup >
2222
2323 <ItemGroup >
24- <PackageReference Include =" Mono.Cecil" Version =" 0.11.4 " />
24+ <PackageReference Include =" Mono.Cecil" Version =" 0.11.5 " />
2525 </ItemGroup >
2626
2727 <ItemGroup >
Original file line number Diff line number Diff line change @@ -624,7 +624,7 @@ public void AreMutable_MatchesFound_ClassSelected()
624624 . That ( )
625625 . ResideInNamespace ( "NetArchTest.TestStructure.Mutability" )
626626 . And ( )
627- . DoNotHaveNameStartingWith ( "ImmutableClass " )
627+ . DoNotHaveNameStartingWith ( "Immutable " )
628628 . Should ( )
629629 . BeMutable ( ) . GetResult ( ) ;
630630
Original file line number Diff line number Diff line change @@ -656,10 +656,11 @@ public void AreImmutable_MatchesFound_ClassSelected()
656656 . And ( )
657657 . AreImmutable ( ) . GetReflectionTypes ( ) ;
658658
659- Assert . Equal ( 3 , result . Count ( ) ) ; // Three types found
659+ Assert . Equal ( 4 , result . Count ( ) ) ; // Three types found
660660 Assert . Contains < Type > ( typeof ( ImmutableClass1 ) , result ) ;
661661 Assert . Contains < Type > ( typeof ( ImmutableClass2 ) , result ) ;
662662 Assert . Contains < Type > ( typeof ( ImmutableClass3 ) , result ) ;
663+ Assert . Contains < Type > ( typeof ( ImmutableRecord1 ) , result ) ;
663664 }
664665
665666 [ Fact ( DisplayName = "Types can be selected for being mutable." ) ]
Original file line number Diff line number Diff line change 11using System . Runtime . CompilerServices ;
22[ assembly: InternalsVisibleTo ( "NetArchTest.UnitTests" ) ]
33
4+ namespace System . Runtime . CompilerServices
5+ {
6+ internal static class IsExternalInit { }
7+ }
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Text ;
4+
5+ namespace NetArchTest . TestStructure . Mutability
6+ {
7+ public record ImmutableRecord1 ( int Property )
8+ {
9+ }
10+ }
Original file line number Diff line number Diff line change 22
33 <PropertyGroup >
44 <TargetFramework >netstandard2.1</TargetFramework >
5+ <LangVersion >9.0</LangVersion >
56 </PropertyGroup >
67
78 <PropertyGroup >
You can’t perform that action at this time.
0 commit comments