33// ReSharper disable ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator
44namespace Pure . DI . Core . Code . Parts ;
55
6- using Microsoft . CodeAnalysis . CSharp ;
7- using Microsoft . CodeAnalysis . CSharp . Syntax ;
8-
96sealed class ScopeConstructorBuilder (
10- ILocks locks ,
117 IConstructors constructors ,
128 ICodeNameProvider codeNameProvider )
139 : IClassPartBuilder
@@ -24,20 +20,13 @@ public CompositionCode Build(CompositionCode composition)
2420 var code = composition . Code ;
2521 var membersCounter = composition . MembersCount ;
2622 var hints = composition . Source . Source . Hints ;
27- var setupContextMembersToCopy = GetSetupContextMembersToCopy ( composition ) ;
23+ var setupContextMembersToCopy = composition . SetupContextMembersToCopy ;
2824 var classArgs = composition . ClassArgs . GetArgsOfKind ( ArgKind . Composition ) . ToList ( ) ;
29- var setupContextArgsToCopy = composition . SetupContextArgs
30- . Where ( arg => arg . Kind != SetupContextKind . RootArgument )
31- . ToList ( ) ;
32- var isLockRequired = composition . IsLockRequired ( locks ) ;
33- var requiresParentScope = composition . Singletons . Length > 0
34- || classArgs . Count > 0
35- || setupContextArgsToCopy . Count > 0
36- || setupContextMembersToCopy . Count > 0
37- || isLockRequired
38- || composition . TotalDisposablesCount > 0 ;
39- var scopeFactoryName = hints . ScopeFactoryName ;
40- var isFactoryMethod = requiresParentScope && ! string . IsNullOrWhiteSpace ( scopeFactoryName ) ;
25+ var setupContextArgsToCopy = composition . SetupContextArgsToCopy ;
26+ var isLockRequired = composition . IsLockRequired ;
27+ var requiresParentScope = composition . RequiresParentScope ;
28+ var scopeFactoryName = composition . ScopeFactoryName ;
29+ var isFactoryMethod = composition . IsFactoryMethod ;
4130 var isCommentsEnabled = hints . IsCommentsEnabled ;
4231 string source , destination ;
4332 if ( isFactoryMethod )
@@ -65,7 +54,7 @@ public CompositionCode Build(CompositionCode composition)
6554
6655 source = $ "{ Names . ParentScopeArgName } .";
6756 destination = "" ;
68- var ctorName = isFactoryMethod ? scopeFactoryName : codeNameProvider . GetConstructorName ( composition . Source . Source . Name . ClassName ) ;
57+ var ctorName = codeNameProvider . GetConstructorName ( composition . Source . Source . Name . ClassName ) ;
6958 code . AppendLine ( $ "internal { ctorName } ({ composition . Source . Source . Name . ClassName } { Names . ParentScopeArgName } )") ;
7059 }
7160
@@ -138,50 +127,4 @@ public CompositionCode Build(CompositionCode composition)
138127 membersCounter ++ ;
139128 return composition with { MembersCount = membersCounter } ;
140129 }
141-
142- private static IReadOnlyCollection < string > GetSetupContextMembersToCopy ( CompositionCode composition )
143- {
144- var memberNames = new HashSet < string > ( StringComparer . Ordinal ) ;
145- foreach ( var setupContextMembers in composition . SetupContextMembers )
146- {
147- foreach ( var member in setupContextMembers . Members )
148- {
149- switch ( member )
150- {
151- case FieldDeclarationSyntax { Declaration : { } declaration } :
152- foreach ( var variable in declaration . Variables )
153- {
154- if ( ! variable . Identifier . IsKind ( SyntaxKind . None ) )
155- {
156- memberNames . Add ( variable . Identifier . ValueText ) ;
157- }
158- }
159-
160- break ;
161-
162- case PropertyDeclarationSyntax property when IsPropertyAssignable ( property ) :
163- if ( ! property . Identifier . IsKind ( SyntaxKind . None ) )
164- {
165- memberNames . Add ( property . Identifier . ValueText ) ;
166- }
167-
168- break ;
169- }
170- }
171- }
172-
173- return memberNames ;
174- }
175-
176- private static bool IsPropertyAssignable ( PropertyDeclarationSyntax property )
177- {
178- if ( property . ExpressionBody is not null || property . AccessorList is not { } accessorList )
179- {
180- return false ;
181- }
182-
183- return accessorList . Accessors . Any ( accessor =>
184- accessor . Kind ( ) is SyntaxKind . SetAccessorDeclaration or SyntaxKind . InitAccessorDeclaration )
185- || accessorList . Accessors . All ( accessor => accessor . Body is null && accessor . ExpressionBody is null ) ;
186- }
187130}
0 commit comments