11// ---------------------------------------------------------------------------------------------------------------------
22// Imports
33// ---------------------------------------------------------------------------------------------------------------------
4- using CodeOfChaos . GeneratorTools ;
5- using JetBrains . Annotations ;
64using Microsoft . CodeAnalysis ;
75using Microsoft . CodeAnalysis . CSharp . Syntax ;
86using Microsoft . CodeAnalysis . Diagnostics ;
@@ -20,8 +18,7 @@ public record InjectableData(
2018 ServiceLifetime ServiceLifetime ,
2119 string ? ServiceTypeName ,
2220 object ? ServiceKey ,
23- bool ServiceKeyIsString ,
24- [ UsedImplicitly ] LocationInfo ? LocationInfo
21+ bool ServiceKeyIsString
2522) {
2623 [ MemberNotNullWhen ( true , nameof ( ServiceKey ) ) ] public bool HasServiceKey => ServiceKey is not null ;
2724
@@ -34,7 +31,7 @@ public static IEnumerable<InjectableData> FromInjectableAttribute(GeneratorAttri
3431
3532 foreach ( AttributeData attributeData in context . Attributes ) {
3633 int lifetime = attributeData . ConstructorArguments [ 0 ] . Value as int ? ?? - 1 ;
37- yield return ExtractServiceData ( classSymbol , classDeclaration , attributeData , ServiceLifetimeUtlities . ToLifetime ( lifetime ) , firstArgumentIndex : 1 ) ;
34+ yield return ExtractServiceData ( classSymbol , attributeData , ServiceLifetimeUtlities . ToLifetime ( lifetime ) , firstArgumentIndex : 1 ) ;
3835 }
3936 }
4037
@@ -45,7 +42,7 @@ public static IEnumerable<InjectableData> FromInjectableAttribute(GeneratorAttri
4542 if ( context . SemanticModel . GetDeclaredSymbol ( classDeclaration ) is not INamedTypeSymbol classSymbol ) yield break ;
4643
4744 foreach ( AttributeData attributeData in context . Attributes ) {
48- yield return ExtractServiceData ( classSymbol , classDeclaration , attributeData , lifetime , firstArgumentIndex ) ;
45+ yield return ExtractServiceData ( classSymbol , attributeData , lifetime , firstArgumentIndex ) ;
4946 }
5047 }
5148
@@ -62,44 +59,42 @@ public static IEnumerable<InjectableData> FromSyntaxAnalyzer(SyntaxNodeAnalysisC
6259 switch ( fullMetadataName ) {
6360 case SourceCodes . InjectableAttributeMetadataName : {
6461 int lifetime = attributeData . ConstructorArguments [ 0 ] . Value as int ? ?? - 1 ;
65- yield return ExtractServiceData ( classSymbol , classDeclaration , attributeData , ServiceLifetimeUtlities . ToLifetime ( lifetime ) , 1 ) ;
62+ yield return ExtractServiceData ( classSymbol , attributeData , ServiceLifetimeUtlities . ToLifetime ( lifetime ) , 1 ) ;
6663 break ;
6764 }
6865
6966 case SourceCodes . InjectableSingletonAttributeMetadataName : {
70- yield return ExtractServiceData ( classSymbol , classDeclaration , attributeData , ServiceLifetime . Singleton , 1 ) ;
67+ yield return ExtractServiceData ( classSymbol , attributeData , ServiceLifetime . Singleton , 1 ) ;
7168 break ;
7269 }
7370
7471 case SourceCodes . InjectableScopedAttributeMetadataName : {
75- yield return ExtractServiceData ( classSymbol , classDeclaration , attributeData , ServiceLifetime . Scoped , 1 ) ;
72+ yield return ExtractServiceData ( classSymbol , attributeData , ServiceLifetime . Scoped , 1 ) ;
7673 break ;
7774 }
7875
7976 case SourceCodes . InjectableTransientAttributeMetadataName : {
80- yield return ExtractServiceData ( classSymbol , classDeclaration , attributeData , ServiceLifetime . Transient , 1 ) ;
77+ yield return ExtractServiceData ( classSymbol , attributeData , ServiceLifetime . Transient , 1 ) ;
8178 break ;
8279 }
8380 }
8481 }
8582 }
8683
87- private static InjectableData ExtractServiceData ( INamedTypeSymbol classSymbol , ClassDeclarationSyntax classDeclaration , AttributeData attributeData , ServiceLifetime lifetime , int firstArgumentIndex ) {
84+ private static InjectableData ExtractServiceData ( INamedTypeSymbol classSymbol , AttributeData attributeData , ServiceLifetime lifetime , int firstArgumentIndex ) {
8885 TypedConstant keyArgument = attributeData . ConstructorArguments . ElementAtOrDefault ( firstArgumentIndex ) ;
8986 ITypeSymbol ? keyType = keyArgument . Type ;
9087 object ? keyObject = keyArgument . Value ;
9188
9289 string ? serviceTypeName = attributeData . AttributeClass ? . TypeArguments . First ( ) . ToString ( ) ;
9390 string className = classSymbol . ToDisplayString ( ) ;
94- LocationInfo ? locationInfo = LocationInfo . From ( classDeclaration . GetLocation ( ) ) ;
9591
9692 return new InjectableData (
9793 className ,
9894 lifetime ,
9995 serviceTypeName ,
10096 keyObject ,
101- keyType is { SpecialType : SpecialType . System_String } ,
102- locationInfo
97+ keyType is { SpecialType : SpecialType . System_String }
10398 ) ;
10499 }
105100}
0 commit comments