File tree 7 files changed +38
-5
lines changed
NetArchTest.Rules.UnitTests
NetArchTest.TestStructure
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
10
10
/// <returns>An indication of whether the property is readonly.</returns>
11
11
public static bool IsReadonly ( this PropertyDefinition propertyDefinition )
12
12
{
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 ;
14
26
}
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
+
16
33
/// <summary>
17
34
/// Tests whether a property is nullable
18
35
/// </summary>
Original file line number Diff line number Diff line change 21
21
</PropertyGroup >
22
22
23
23
<ItemGroup >
24
- <PackageReference Include =" Mono.Cecil" Version =" 0.11.4 " />
24
+ <PackageReference Include =" Mono.Cecil" Version =" 0.11.5 " />
25
25
</ItemGroup >
26
26
27
27
<ItemGroup >
Original file line number Diff line number Diff line change @@ -624,7 +624,7 @@ public void AreMutable_MatchesFound_ClassSelected()
624
624
. That ( )
625
625
. ResideInNamespace ( "NetArchTest.TestStructure.Mutability" )
626
626
. And ( )
627
- . DoNotHaveNameStartingWith ( "ImmutableClass " )
627
+ . DoNotHaveNameStartingWith ( "Immutable " )
628
628
. Should ( )
629
629
. BeMutable ( ) . GetResult ( ) ;
630
630
Original file line number Diff line number Diff line change @@ -656,10 +656,11 @@ public void AreImmutable_MatchesFound_ClassSelected()
656
656
. And ( )
657
657
. AreImmutable ( ) . GetReflectionTypes ( ) ;
658
658
659
- Assert . Equal ( 3 , result . Count ( ) ) ; // Three types found
659
+ Assert . Equal ( 4 , result . Count ( ) ) ; // Three types found
660
660
Assert . Contains < Type > ( typeof ( ImmutableClass1 ) , result ) ;
661
661
Assert . Contains < Type > ( typeof ( ImmutableClass2 ) , result ) ;
662
662
Assert . Contains < Type > ( typeof ( ImmutableClass3 ) , result ) ;
663
+ Assert . Contains < Type > ( typeof ( ImmutableRecord1 ) , result ) ;
663
664
}
664
665
665
666
[ Fact ( DisplayName = "Types can be selected for being mutable." ) ]
Original file line number Diff line number Diff line change 1
1
using System . Runtime . CompilerServices ;
2
2
[ assembly: InternalsVisibleTo ( "NetArchTest.UnitTests" ) ]
3
3
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 2
2
3
3
<PropertyGroup >
4
4
<TargetFramework >netstandard2.1</TargetFramework >
5
+ <LangVersion >9.0</LangVersion >
5
6
</PropertyGroup >
6
7
7
8
<PropertyGroup >
You can’t perform that action at this time.
0 commit comments