File tree Expand file tree Collapse file tree 3 files changed +30
-4
lines changed
Immutype.Tests/Integration Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 1717 <!-- <AnalyzerRoslynVersion Condition="'$(AnalyzerRoslynVersion)'==''">3.8</AnalyzerRoslynVersion>
1818 <AnalyzerRoslynPackageVersion Condition="'$(AnalyzerRoslynPackageVersion)'==''">3.8.0</AnalyzerRoslynPackageVersion>-->
1919
20- <DefineConstants Condition =" '$(AnalyzerRoslynVersion)'=='4.0'" >ROSLYN40</DefineConstants >
21- <DefineConstants Condition =" '$(AnalyzerRoslynVersion)'=='3.8'" >ROSLYN38</DefineConstants >
20+ <DefineConstants Condition =" '$(AnalyzerRoslynVersion)'=='4.0'" >$(DefineConstants); ROSLYN40</DefineConstants >
21+ <DefineConstants Condition =" '$(AnalyzerRoslynVersion)'=='3.8'" >$(DefineConstants); ROSLYN38</DefineConstants >
2222 </PropertyGroup >
2323
2424 <ItemGroup >
Original file line number Diff line number Diff line change @@ -62,13 +62,31 @@ namespace Sample
6262 {
6363 using System;
6464
65- [Immutype.TargetAttribute() ]
65+ [Immutype.Target ]
6666 public record struct Rec(int val);
6767 }" . Run ( out var generatedCode , new RunOptions { Statements = statements } ) ;
6868
6969 // Then
7070 output . ShouldBe ( new [ ] { "Rec { val = 99 }" } , generatedCode ) ;
7171 }
72+
73+ [ Fact ]
74+ public void ShouldSupportBlockFreeNamespace ( )
75+ {
76+ // Given
77+ const string statements = "System.Console.WriteLine(new Rec(33).WithVal(99));" ;
78+
79+ // When
80+ var output = @"
81+ namespace Sample;
82+ using System;
83+ [Immutype.Target]
84+ public record struct Rec(int val);
85+ " . Run ( out var generatedCode , new RunOptions { Statements = statements } ) ;
86+
87+ // Then
88+ output . ShouldBe ( new [ ] { "Rec { val = 99 }" } , generatedCode ) ;
89+ }
7290#endif
7391
7492 [ Fact ]
Original file line number Diff line number Diff line change @@ -20,7 +20,15 @@ public ExtensionsFactory(IMethodsFactory methodsFactory) =>
2020 public IEnumerable < Source > Create ( GenerationContext < TypeDeclarationSyntax > context , IReadOnlyList < ParameterSyntax > parameters )
2121 {
2222 var typeDeclarationSyntax = context . Syntax ;
23- var ns = typeDeclarationSyntax . Ancestors ( ) . OfType < NamespaceDeclarationSyntax > ( ) . Reverse ( ) . ToArray ( ) ;
23+ var ns = typeDeclarationSyntax . Ancestors ( )
24+ #if ROSLYN38
25+ . OfType < NamespaceDeclarationSyntax > ( )
26+ #else
27+ . OfType < BaseNamespaceDeclarationSyntax > ( )
28+ #endif
29+ . Reverse ( )
30+ . ToArray ( ) ;
31+
2432 var typeName =
2533 string . Join ( "." , ns . Select ( i => i . Name . ToString ( ) )
2634 . Concat ( new [ ] { typeDeclarationSyntax . Identifier . Text + typeDeclarationSyntax . TypeParameterList } ) ) ;
You can’t perform that action at this time.
0 commit comments