Skip to content

Commit 09258f5

Browse files
committed
#127 Nullability issue
1 parent 06c3e6f commit 09258f5

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/Injectio.Generators/ServiceRegistrationGenerator.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ namespace Injectio.Generators;
1414
[Generator]
1515
public class ServiceRegistrationGenerator : IIncrementalGenerator
1616
{
17+
private static readonly SymbolDisplayFormat _fullyQualifiedNullableFormat =
18+
SymbolDisplayFormat.FullyQualifiedFormat.AddMiscellaneousOptions(
19+
SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier
20+
);
21+
1722
public void Initialize(IncrementalGeneratorInitializationContext context)
1823
{
1924
var pipeline = context.SyntaxProvider.CreateSyntaxProvider(
@@ -134,7 +139,7 @@ private static bool SyntacticPredicate(SyntaxNode syntaxNode, CancellationToken
134139

135140
var registration = new ModuleRegistration
136141
(
137-
ClassName: methodSymbol.ContainingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
142+
ClassName: methodSymbol.ContainingType.ToDisplayString(_fullyQualifiedNullableFormat),
138143
MethodName: methodSymbol.Name,
139144
IsStatic: methodSymbol.IsStatic,
140145
HasTagCollection: hasTagCollection
@@ -252,12 +257,12 @@ private static (EquatableArray<Diagnostic> diagnostics, bool hasServiceCollectio
252257

253258
if (typeParameter.Name == "TService" || index == 0)
254259
{
255-
var service = typeArgument.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
260+
var service = typeArgument.ToDisplayString(_fullyQualifiedNullableFormat);
256261
serviceTypes.Add(service);
257262
}
258263
else if (typeParameter.Name == "TImplementation" || index == 1)
259264
{
260-
implementationType = typeArgument.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
265+
implementationType = typeArgument.ToDisplayString(_fullyQualifiedNullableFormat);
261266
}
262267
}
263268
}
@@ -318,7 +323,7 @@ private static (EquatableArray<Diagnostic> diagnostics, bool hasServiceCollectio
318323
// no implementation type set, use class attribute is on
319324
if (implementationType.IsNullOrWhiteSpace())
320325
{
321-
implementationType = classSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
326+
implementationType = classSymbol.ToDisplayString(_fullyQualifiedNullableFormat);
322327
}
323328

324329
// add implemented interfaces
@@ -327,7 +332,7 @@ private static (EquatableArray<Diagnostic> diagnostics, bool hasServiceCollectio
327332
{
328333
foreach (var implementedInterface in classSymbol.AllInterfaces)
329334
{
330-
var interfaceName = implementedInterface.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
335+
var interfaceName = implementedInterface.ToDisplayString(_fullyQualifiedNullableFormat);
331336
serviceTypes.Add(interfaceName);
332337
}
333338
}

tests/Injectio.Tests.Library/Service.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,10 @@ public enum ServiceType
138138
Charlie,
139139
Delta
140140
}
141+
142+
[RegisterScoped]
143+
public class Service : IService<Input, string?>;
144+
public class Input : IInput<string?>;
145+
146+
public interface IService<TInput, TOutput> where TInput : IInput<TOutput>;
147+
public interface IInput<TOutput>;

0 commit comments

Comments
 (0)