Null Object Generator
[GenerateNullObject] generates a sealed Null Object implementation for an interface contract.
[GenerateNullObject(TypeName = "NullInventoryNotifier")]
public interface IInventoryNotifier
{
[NullObjectDefault(false)]
bool CanDeliver { get; }
[NullObjectDefault("suppressed")]
string Notify(string sku);
}
Generated output includes:
- a sealed implementation of the contract
- a static
Instanceproperty - no-op
voidmethods - deterministic defaults for strings, booleans, numeric values, arrays,
Task,Task<T>,ValueTask, andValueTask<T> - per-member defaults through
[NullObjectDefault]
Use the generated implementation directly or wrap it with NullObject<TContract> for consistent dependency injection registration.