Skip to content

Commit 58aceaa

Browse files
committed
fix: Nullable
1 parent dac22f4 commit 58aceaa

9 files changed

Lines changed: 90 additions & 14 deletions

examples/Simple/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// Add a notification handler for "WriteLineNotification" with-in the mediator namespace "upper"
2323
builder.AddNotificationHandler((WriteLineNotification notification) =>
2424
{
25-
Console.WriteLine(notification.Message.ToUpper());
25+
Console.WriteLine(notification.Message?.ToUpper());
2626
});
2727
});
2828

@@ -36,6 +36,6 @@
3636
await mediator.WriteLineAsync(message);
3737
await mediator.WriteLineAsync(upperNs, message);
3838

39-
public record struct WriteLineNotification(string Message) : INotification;
39+
public record struct WriteLineNotification(string? Message) : INotification;
4040

41-
public record struct GetMessage : IRequest<string>;
41+
public record struct GetMessage : IRequest<string?>;

examples/Simple/Simple.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<IsPackable>false</IsPackable>
9+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
910
</PropertyGroup>
1011

1112
<ItemGroup>

src/Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project>
22

33
<PropertyGroup>
4-
<Version>1.0.0-alpha.20</Version>
5-
<PackageVersion>1.0.0-alpha.20</PackageVersion>
4+
<Version>1.0.0-alpha.21</Version>
5+
<PackageVersion>1.0.0-alpha.21</PackageVersion>
66
<Authors>Zapto</Authors>
77
<RepositoryUrl>https://github.com/zapto-dev/Mediator</RepositoryUrl>
88
<Copyright>Copyright © 2025 Zapto</Copyright>

src/Mediator.SourceGenerator/SenderGenerator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,11 @@ void AppendMethodGenerics()
368368

369369
if (parameter.Name == parameterName)
370370
{
371-
sb.AppendType(result.Type, false);
371+
sb.AppendType(result.Type);
372372
}
373373
else if (typeNames.TryGetValue(parameter.Name, out var result))
374374
{
375-
sb.AppendType(result, false);
375+
sb.AppendType(result);
376376
}
377377

378378
if (i != length - 1)
@@ -411,7 +411,7 @@ void AppendMethodGenerics()
411411

412412
AppendGenerics();
413413
sb.Append("(this ");
414-
sb.AppendType(sender, false);
414+
sb.AppendType(sender);
415415
sb.Append(" sender, ");
416416
sb.AppendParameterDefinitions(method.Parameters, t =>
417417
{
@@ -483,7 +483,7 @@ void AppendMethodGenerics()
483483

484484
AppendGenerics();
485485
sb.Append("(this ");
486-
sb.AppendType(sender, false);
486+
sb.AppendType(sender);
487487
sb.Append(" sender, ");
488488

489489
var hasRequiredProperties = FillParameters(result, constructor, parameters);
@@ -524,7 +524,7 @@ void AppendMethodGenerics()
524524
}
525525

526526
sb.Append("new ");
527-
sb.AppendType(result.Type, false);
527+
sb.AppendType(result.Type);
528528
sb.Append('(');
529529
sb.AppendParameters(constructor.Parameters);
530530
sb.Append(')');
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//HintName: Request_Extensions.g.cs
2+
#nullable enable
3+
4+
public static partial class SenderExtensions
5+
{
6+
[global::System.Diagnostics.DebuggerStepThrough]
7+
public static global::System.Threading.Tasks.ValueTask<string?> RequestAsync(this global::Zapto.Mediator.ISender sender, global::Request request, global::System.Threading.CancellationToken cancellationToken = default)
8+
=> sender.Send<global::Request, string?>(request, cancellationToken);
9+
10+
[global::System.Diagnostics.DebuggerStepThrough]
11+
public static global::System.Threading.Tasks.ValueTask<string?> RequestAsync(this global::Zapto.Mediator.ISender sender, global::System.Threading.CancellationToken cancellationToken = default)
12+
=> sender.Send<global::Request, string?>(new global::Request(), cancellationToken);
13+
14+
[global::System.Diagnostics.DebuggerStepThrough]
15+
public static global::System.Threading.Tasks.ValueTask<string?> RequestAsync(this global::Zapto.Mediator.ISender sender, global::Zapto.Mediator.MediatorNamespace ns, global::Request request, global::System.Threading.CancellationToken cancellationToken = default)
16+
=> sender.Send<global::Request, string?>(ns, request, cancellationToken);
17+
18+
[global::System.Diagnostics.DebuggerStepThrough]
19+
public static global::System.Threading.Tasks.ValueTask<string?> RequestAsync(this global::Zapto.Mediator.ISender sender, global::Zapto.Mediator.MediatorNamespace ns, global::System.Threading.CancellationToken cancellationToken = default)
20+
=> sender.Send<global::Request, string?>(ns, new global::Request(), cancellationToken);
21+
}

tests/Mediator.SourceGenerator.Tests/GeneratorTests.GenerateNullableClass#Request_Extensions.g.verified.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ public static partial class SenderExtensions
55
{
66
[global::System.Diagnostics.DebuggerStepThrough]
77
public static global::System.Threading.Tasks.ValueTask<string?> RequestAsync(this global::Zapto.Mediator.ISender sender, global::Request request, global::System.Threading.CancellationToken cancellationToken = default)
8-
=> sender.Send<global::Request, string>(request, cancellationToken);
8+
=> sender.Send<global::Request, string?>(request, cancellationToken);
99

1010
[global::System.Diagnostics.DebuggerStepThrough]
1111
public static global::System.Threading.Tasks.ValueTask<string?> RequestAsync(this global::Zapto.Mediator.ISender sender, global::System.Threading.CancellationToken cancellationToken = default)
12-
=> sender.Send<global::Request, string>(new global::Request(), cancellationToken);
12+
=> sender.Send<global::Request, string?>(new global::Request(), cancellationToken);
1313

1414
[global::System.Diagnostics.DebuggerStepThrough]
1515
public static global::System.Threading.Tasks.ValueTask<string?> RequestAsync(this global::Zapto.Mediator.ISender sender, global::Zapto.Mediator.MediatorNamespace ns, global::Request request, global::System.Threading.CancellationToken cancellationToken = default)
16-
=> sender.Send<global::Request, string>(ns, request, cancellationToken);
16+
=> sender.Send<global::Request, string?>(ns, request, cancellationToken);
1717

1818
[global::System.Diagnostics.DebuggerStepThrough]
1919
public static global::System.Threading.Tasks.ValueTask<string?> RequestAsync(this global::Zapto.Mediator.ISender sender, global::Zapto.Mediator.MediatorNamespace ns, global::System.Threading.CancellationToken cancellationToken = default)
20-
=> sender.Send<global::Request, string>(ns, new global::Request(), cancellationToken);
20+
=> sender.Send<global::Request, string?>(ns, new global::Request(), cancellationToken);
2121
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//HintName: Request_Extensions.g.cs
2+
#nullable enable
3+
4+
public static partial class SenderExtensions
5+
{
6+
[global::System.Diagnostics.DebuggerStepThrough]
7+
public static global::System.Threading.Tasks.ValueTask<string?> RequestAsync(this global::Zapto.Mediator.ISender sender, global::Request request, global::System.Threading.CancellationToken cancellationToken = default)
8+
=> sender.Send<global::Request, string?>(request, cancellationToken);
9+
10+
[global::System.Diagnostics.DebuggerStepThrough]
11+
public static global::System.Threading.Tasks.ValueTask<string?> RequestAsync(this global::Zapto.Mediator.ISender sender, global::System.Threading.CancellationToken cancellationToken = default)
12+
=> sender.Send<global::Request, string?>(new global::Request(), cancellationToken);
13+
14+
[global::System.Diagnostics.DebuggerStepThrough]
15+
public static global::System.Threading.Tasks.ValueTask<string?> RequestAsync(this global::Zapto.Mediator.ISender sender, global::Zapto.Mediator.MediatorNamespace ns, global::Request request, global::System.Threading.CancellationToken cancellationToken = default)
16+
=> sender.Send<global::Request, string?>(ns, request, cancellationToken);
17+
18+
[global::System.Diagnostics.DebuggerStepThrough]
19+
public static global::System.Threading.Tasks.ValueTask<string?> RequestAsync(this global::Zapto.Mediator.ISender sender, global::Zapto.Mediator.MediatorNamespace ns, global::System.Threading.CancellationToken cancellationToken = default)
20+
=> sender.Send<global::Request, string?>(ns, new global::Request(), cancellationToken);
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//HintName: Request_Extensions.g.cs
2+
#nullable enable
3+
4+
public static partial class SenderExtensions
5+
{
6+
[global::System.Diagnostics.DebuggerStepThrough]
7+
public static global::System.Threading.Tasks.ValueTask<string?> RequestAsync(this global::Zapto.Mediator.ISender sender, global::Request request, global::System.Threading.CancellationToken cancellationToken = default)
8+
=> sender.Send<global::Request, string?>(request, cancellationToken);
9+
10+
[global::System.Diagnostics.DebuggerStepThrough]
11+
public static global::System.Threading.Tasks.ValueTask<string?> RequestAsync(this global::Zapto.Mediator.ISender sender, global::System.Threading.CancellationToken cancellationToken = default)
12+
=> sender.Send<global::Request, string?>(new global::Request(), cancellationToken);
13+
14+
[global::System.Diagnostics.DebuggerStepThrough]
15+
public static global::System.Threading.Tasks.ValueTask<string?> RequestAsync(this global::Zapto.Mediator.ISender sender, global::Zapto.Mediator.MediatorNamespace ns, global::Request request, global::System.Threading.CancellationToken cancellationToken = default)
16+
=> sender.Send<global::Request, string?>(ns, request, cancellationToken);
17+
18+
[global::System.Diagnostics.DebuggerStepThrough]
19+
public static global::System.Threading.Tasks.ValueTask<string?> RequestAsync(this global::Zapto.Mediator.ISender sender, global::Zapto.Mediator.MediatorNamespace ns, global::System.Threading.CancellationToken cancellationToken = default)
20+
=> sender.Send<global::Request, string?>(ns, new global::Request(), cancellationToken);
21+
}

tests/Mediator.SourceGenerator.Tests/GeneratorTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ public record Request : IRequest<string?>;";
7474
return TestHelper.Verify<SenderGenerator>(source);
7575
}
7676

77+
[Fact]
78+
public Task GenerateNullableClassDeep()
79+
{
80+
const string source = @"
81+
using MediatR;
82+
83+
public interface IGetRequest<T> : IRequest<T?>;
84+
public record Request : IGetRequest<string>;";
85+
86+
return TestHelper.Verify<SenderGenerator>(source);
87+
}
88+
7789
[Fact]
7890
public Task GenerateNullableValueType()
7991
{

0 commit comments

Comments
 (0)