OverrideAccessors(IAdviser<IFieldOrPropertyOrIndexer>, in GetterTemplateSelector, string?, object?, object?)
Overrides a field, property, or indexer by specifying templates for the getter and/or setter. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to a different field, property or indexer than the current one.
Declaration
public static IOverrideAdviceResult<IPropertyOrIndexer> OverrideAccessors(this IAdviser<IFieldOrPropertyOrIndexer> adviser, in GetterTemplateSelector getTemplate = default, string? setTemplate = null, object? args = null, object? tags = null)Parameters
| Type | Name | Description |
|---|---|---|
| IAdviser<IFieldOrPropertyOrIndexer> | adviser | An adviser for a field, property or indexer. |
| GetterTemplateSelector | getTemplate | The name of the method of the aspect class whose implementation will be used as a template for the getter, or |
| string | setTemplate | The name of the method of the aspect class whose implementation will be used as a template for the setter, or |
| object | args | An optional object (typically of anonymous type) whose properties map to template method parameters or type parameters. See Sharing state with adviceSharing state with advice for details. |
| object | tags | An optional object (typically of anonymous type) passed to the template and accessible via |
Returns
| Type | Description |
|---|---|
| IOverrideAdviceResult<IPropertyOrIndexer> | An IOverrideAdviceResult<T> exposing the overridden IPropertyOrIndexer. |
Remarks
This method provides fine-grained control over accessor overriding by using separate method templates for getters and setters.
Within templates, use meta.Target.FieldOrProperty.Value (for fields/properties) or meta.Target.Indexer[...].Value
(for indexers) to access the underlying value, and meta.Proceed() to invoke the original accessor.
When applied to a field or auto-property, a backing field is automatically introduced.
See Also
OverrideAccessors(IAdviser<IFieldOrProperty>, in GetterTemplateSelector, string?, object?, object?)
Overrides a field or property by specifying a method template for the getter, the setter, or both. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to another field or property than the current one.
Declaration
public static IOverrideAdviceResult<IProperty> OverrideAccessors(this IAdviser<IFieldOrProperty> adviser, in GetterTemplateSelector getTemplate = default, string? setTemplate = null, object? args = null, object? tags = null)Parameters
| Type | Name | Description |
|---|---|---|
| IAdviser<IFieldOrProperty> | adviser | An adviser for a field or property. |
| GetterTemplateSelector | getTemplate | The name of the method of the aspect class whose implementation will be used as a template for the getter, or |
| string | setTemplate | The name of the method of the aspect class whose implementation will be used as a template for the setter, or |
| object | args | An optional object (typically of anonymous type) whose properties map to template method parameters or type parameters. See Sharing state with adviceSharing state with advice for details. |
| object | tags | An optional object (typically of anonymous type) passed to the template and accessible via |
Returns
| Type | Description |
|---|---|
| IOverrideAdviceResult<IProperty> | An IOverrideAdviceResult<T> exposing the overridden IProperty. |
See Also
OverrideAccessors(IAdviser<IIndexer>, in GetterTemplateSelector, string?, object?, object?)
Overrides an indexer by specifying a method template for the getter, the setter, or both. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to another indexer than the current one.
Declaration
public static IOverrideAdviceResult<IIndexer> OverrideAccessors(this IAdviser<IIndexer> adviser, in GetterTemplateSelector getTemplate = default, string? setTemplate = null, object? args = null, object? tags = null)Parameters
| Type | Name | Description |
|---|---|---|
| IAdviser<IIndexer> | adviser | An adviser for an indexer. |
| GetterTemplateSelector | getTemplate | The name of the method of the aspect class whose implementation will be used as a template for the getter, or |
| string | setTemplate | The name of the method of the aspect class whose implementation will be used as a template for the setter, or |
| object | args | An optional object (typically of anonymous type) whose properties map to template method parameters or type parameters. See Sharing state with adviceSharing state with advice for details. |
| object | tags | An optional object (typically of anonymous type) passed to the template and accessible via |
Returns
| Type | Description |
|---|---|
| IOverrideAdviceResult<IIndexer> | An IOverrideAdviceResult<T> exposing the overridden IIndexer. |
See Also
OverrideAccessors(IAdviser<IEvent>, string?, string?, string?, string?, object?, object?)
Overrides an event by specifying a template for the adder, the remover, and/or the invocation interception. Use the With<TNewDeclaration>(TNewDeclaration) method to override a different event than the current one.
Declaration
public static IOverrideAdviceResult<IEvent> OverrideAccessors(this IAdviser<IEvent> adviser, string? addTemplate = null, string? removeTemplate = null, string? raiseTemplate = null, string? invokeTemplate = null, object? args = null, object? tags = null)Parameters
| Type | Name | Description |
|---|---|---|
| IAdviser<IEvent> | adviser | An adviser for an event. |
| string | addTemplate | The name of the method of the aspect class whose type and implementation will be used as a template for the adder, or |
| string | removeTemplate | The name of the method of the aspect class whose type and implementation will be used as a template for the remover, or |
| string | raiseTemplate | Reserved for future use (not implemented). |
| string | invokeTemplate | The name of the method of the aspect class whose type and implementation will be used as a template for intercepting invocation of
the event's handlers. This template is invoked once per event handler when the event is raised. The signature of this method must be
|
| object | args | An optional object (typically of anonymous type) whose properties map to template method parameters or type parameters. See Sharing state with adviceSharing state with advice for details. |
| object | tags | An optional object (typically of anonymous type) passed to the template and accessible via |
Returns
| Type | Description |
|---|---|
| IOverrideAdviceResult<IEvent> | An IOverrideAdviceResult<T> exposing the overridden IEvent. |
Remarks
This is the programmatic way to override events from BuildAspect(IAspectBuilder<T>). For a simplified approach when the aspect's only purpose is to override an event, derive from OverrideEventAspect instead.
When applied to a field-like event, it is automatically transformed into an explicitly implemented event with a backing field, similar to how auto-properties are transformed.
The invokeTemplate provides powerful per-handler interception capabilities. Since it's invoked once per handler,
you can implement patterns like exception handling with handler removal, async execution, or handler filtering. Within the template,
access event metadata via meta.Target.Event and programmatically add/remove handlers using meta.Target.Event.Add(handler)
and meta.Target.Event.Remove(handler).
Performance Note: Overriding the invoke operation uses an EventBroker<TDelegate, TArgs, TState> pattern which adds memory overhead (one broker instance per event per object instance) and allocates memory during event invocation. This may affect performance for high-frequency events.
Limitations: Delegate signatures with non-void return types or with ref/out parameters are not
supported. Only handlers added through the event's add/remove accessors will be intercepted.