Class BuilderMetadata
Stores extension-defined builder settings keyed by their CLR type.
Inherited Members
Namespace: NanoRoute
Assembly: NanoRoute.dll
Syntax
public sealed class BuilderMetadata
Remarks
This type is public so third-party builder extensions can keep scoped build-time settings behind their own
module-specific APIs. Application code usually should prefer those APIs, such as ConfigureXxx()
methods, instead of reading or writing metadata directly.
Prefix builders receive a scoped copy of the parent metadata when they are created. Later changes made in either scope stay local to that scope.
Examples
builder.Metadata.Set(new MyFeatureOptions { Enabled = true });
MyFeatureOptions options = builder.Metadata.GetOrDefault(MyFeatureOptions.Default);
Methods
GetOrDefault<T>(T)
Gets the metadata value registered for T, or defaultValue when
no value has been registered in this scope.
Declaration
public T GetOrDefault<T>(T defaultValue) where T : notnull
Parameters
| Type | Name | Description |
|---|---|---|
| T | defaultValue | The value to return when the metadata entry is absent. |
Returns
| Type | Description |
|---|---|
| T | The registered metadata value, or |
Type Parameters
| Name | Description |
|---|---|
| T | The metadata value type. |
Examples
MyFeatureOptions options = builder.Metadata.GetOrDefault(MyFeatureOptions.Default);
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
Remove<T>()
Removes the metadata value registered for T.
Declaration
public bool Remove<T>() where T : notnull
Returns
| Type | Description |
|---|---|
| bool |
Type Parameters
| Name | Description |
|---|---|
| T | The metadata value type. |
Examples
bool removed = builder.Metadata.Remove<MyFeatureOptions>();
Set<T>(T)
Registers or replaces the metadata value for T.
Declaration
public void Set<T>(T value) where T : notnull
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The metadata value. |
Type Parameters
| Name | Description |
|---|---|
| T | The metadata value type. |
Examples
builder.Metadata.Set(new MyFeatureOptions { Enabled = true });
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
TryGet<T>(out T?)
Tries to get the metadata value registered for T.
Declaration
public bool TryGet<T>(out T? value) where T : notnull
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The registered metadata value, when one exists. |
Returns
| Type | Description |
|---|---|
| bool |
Type Parameters
| Name | Description |
|---|---|
| T | The metadata value type. |
Examples
if (builder.Metadata.TryGet(out MyFeatureOptions? options))
{
EnableFeature(options);
}