Sencilla.Messaging.SourceGenerator
10.0.62
dotnet add package Sencilla.Messaging.SourceGenerator --version 10.0.62
NuGet\Install-Package Sencilla.Messaging.SourceGenerator -Version 10.0.62
<PackageReference Include="Sencilla.Messaging.SourceGenerator" Version="10.0.62"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Sencilla.Messaging.SourceGenerator" Version="10.0.62" />
<PackageReference Include="Sencilla.Messaging.SourceGenerator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Sencilla.Messaging.SourceGenerator --version 10.0.62
#r "nuget: Sencilla.Messaging.SourceGenerator, 10.0.62"
#:package Sencilla.Messaging.SourceGenerator@10.0.62
#addin nuget:?package=Sencilla.Messaging.SourceGenerator&version=10.0.62
#tool nuget:?package=Sencilla.Messaging.SourceGenerator&version=10.0.62
Sencilla.Messaging.SourceGenerator
A source generator that automatically creates extension methods for IMessageDispatcher based on command classes marked with the [ExtendDispatcher] attribute.
Installation
Install the NuGet package in your project:
dotnet add package Sencilla.Messaging.SourceGenerator
Or via Package Manager:
<PackageReference Include="Sencilla.Messaging.SourceGenerator" Version="9.0.0" />
Usage
1. Mark your command class with the attribute
using Sencilla.Messaging;
[ExtendDispatcher(Method = "PrepareSpreadImage")]
public class PrepareSpreadImageCommand
{
public int ImageId { get; set; }
public string ProcessingType { get; set; } = "Standard";
public required string TargetPath { get; set; }
}
2. Use the generated extension method
using Sencilla.Messaging;
using Sencilla.Messaging.Extensions; // Generated namespace
public class ImageProcessor
{
private readonly IMessageDispatcher _dispatcher;
public ImageProcessor(IMessageDispatcher dispatcher)
{
_dispatcher = dispatcher;
}
public async Task ProcessImageAsync(int imageId, string targetPath)
{
// Instead of manually creating the command:
// await _dispatcher.Send(new PrepareSpreadImageCommand
// {
// ImageId = imageId,
// TargetPath = targetPath
// });
// Use the generated extension method:
await _dispatcher.PrepareSpreadImage(
imageId: imageId,
targetPath: targetPath,
processingType: "Enhanced" // Optional with default
);
}
}
Generated Code
For the example above, the generator creates:
// <auto-generated />
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Sencilla.Messaging.Extensions
{
/// <summary>
/// Auto-generated extension methods for IMessageDispatcher.
/// </summary>
public static class MessageDispatcherExtensions
{
/// <summary>
/// Sends a PrepareSpreadImageCommand command.
/// </summary>
/// <param name="dispatcher">The message dispatcher.</param>
/// <param name="imageId">The ImageId value.</param>
/// <param name="targetPath">The TargetPath value.</param>
/// <param name="processingType">The ProcessingType value.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task representing the asynchronous operation.</returns>
public static Task PrepareSpreadImage(
this IMessageDispatcher dispatcher,
int imageId,
string targetPath,
string processingType = "Standard",
CancellationToken cancellationToken = default)
{
return dispatcher.Send(new PrepareSpreadImageCommand
{
ImageId = imageId,
TargetPath = targetPath,
ProcessingType = processingType
}, cancellationToken);
}
}
}
Features
- Automatic Extension Generation: Creates strongly-typed extension methods
- Support for Default Values: Respects property initializers as default parameter values
- Required Properties: Handles
requiredproperties as mandatory parameters - Custom Method Names: Use
Methodproperty in attribute to specify custom method names - Null Safety: Full nullable reference type support
- IDE Integration: Full IntelliSense and compile-time checking
Attribute Options
ExtendDispatcherAttribute
Method(optional): Specifies the name of the generated extension method. If not provided, uses the class name (removing "Command" suffix if present).
Requirements
- .NET Standard 2.0+ or .NET Core 2.0+ or .NET Framework 4.6.1+
- C# 8.0+ for nullable reference types support
Examples
Basic Command
[ExtendDispatcher]
public class SendEmail
{
public required string To { get; set; }
public required string Subject { get; set; }
public required string Body { get; set; }
}
// Usage:
await dispatcher.SendEmail(
to: "user@example.com",
subject: "Hello",
body: "Hello World!"
);
Command with Default Values
[ExtendDispatcher(Method = "ProcessOrder")]
public class ProcessOrderCommand
{
public required int OrderId { get; set; }
public bool HighPriority { get; set; } = false;
public string ProcessingMode { get; set; } = "Standard";
}
// Usage:
await dispatcher.ProcessOrder(orderId: 123); // Uses defaults
await dispatcher.ProcessOrder(orderId: 123, highPriority: true); // Override defaults
Complex Properties
[ExtendDispatcher]
public class CreateUser
{
public required string Email { get; set; }
public required string FirstName { get; set; }
public required string LastName { get; set; }
public List<string> Roles { get; set; } = new();
public DateTime? LastLoginDate { get; set; }
}
// Usage:
await dispatcher.CreateUser(
email: "john@example.com",
firstName: "John",
lastName: "Doe",
roles: new List<string> { "User", "Admin" },
lastLoginDate: DateTime.Now
);
Troubleshooting
Generated files not appearing
- Clean and rebuild your solution
- Ensure the package is properly installed
- Check that your command classes are marked with
[ExtendDispatcher] - Verify that command classes have public properties with public getters and setters
Compilation errors
- Ensure you're using
Sencilla.Messaging.Extensionsnamespace - Check that all required properties are provided as parameters
- Verify that the
IMessageDispatcherinterface is properly referenced
License
This package is licensed under the MIT License. { ImageId = imageId, }, cancellationToken); } }
## Complex Example
```csharp
[GenerateMessageDispatcherExtension(MethodName = "ProcessOrderImage")]
public class ProcessImageCommand
{
public int OrderId { get; set; }
public string FilePath { get; set; } = string.Empty;
public int Width { get; set; }
public int Height { get; set; }
public double Quality { get; set; }
public DateTime Deadline { get; set; }
public bool IsUrgent { get; set; }
}
This generates:
public static Task ProcessOrderImage(this IMessageDispatcher dispatcher,
int orderId,
string filePath,
int width,
int height,
double quality,
DateTime deadline,
bool isUrgent,
CancellationToken cancellationToken = default)
{
return dispatcher.Send(new ProcessImageCommand
{
OrderId = orderId,
FilePath = filePath,
Width = width,
Height = height,
Quality = quality,
Deadline = deadline,
IsUrgent = isUrgent,
}, cancellationToken);
}
Features
- ✅ Automatic method name generation: Uses class name by default, removes "Command" suffix
- ✅ Custom method names: Use
MethodNameparameter in the attribute - ✅ Type-safe parameters: All properties become method parameters with correct types
- ✅ Parameter name conversion: PascalCase properties become camelCase parameters
- ✅ Documentation generation: Automatic XML documentation for generated methods
- ✅ Cancellation token support: All generated methods include optional CancellationToken
- ✅ Multiple commands: Generate extensions for multiple command classes in the same project
Requirements
- The command class must have public properties with public getters and setters
- The class must be marked with
[GenerateMessageDispatcherExtension]attribute - The project must reference the
Sencilla.Messaging.SourceGeneratorsproject as an Analyzer
Installation
Add the source generator project reference to your project file:
<ItemGroup>
<ProjectReference Include="../../libs/SourceGenerator/Sencilla.Messaging.SourceGenerators.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="true" />
</ItemGroup>
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.62 | 102 | 9/9/2026 |
| 10.0.61 | 76 | 9/9/2026 |
| 10.0.59 | 166 | 8/21/2026 |
| 10.0.58 | 93 | 8/21/2026 |
| 10.0.57 | 96 | 8/21/2026 |
| 10.0.56 | 92 | 8/21/2026 |
| 10.0.55 | 112 | 8/18/2026 |
| 10.0.54 | 99 | 8/14/2026 |
| 10.0.53 | 110 | 8/10/2026 |
| 10.0.52 | 104 | 8/7/2026 |
| 10.0.51 | 106 | 8/5/2026 |
| 10.0.50 | 97 | 8/5/2026 |
| 10.0.49 | 117 | 7/31/2026 |
| 10.0.48 | 130 | 7/23/2026 |
| 10.0.47 | 114 | 7/17/2026 |
| 10.0.46 | 131 | 7/13/2026 |
| 10.0.45 | 123 | 7/5/2026 |
| 10.0.44 | 128 | 6/23/2026 |
| 10.0.43 | 113 | 6/23/2026 |
| 10.0.42 | 116 | 6/22/2026 |