Provides read-only dictionary access to tags passed from the BuildAspect(IAspectBuilder<T>) method to templates. Accessible in templates via Tags.
Namespace: Metalama.Framework.Aspects
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
public interface IObjectReader : IReadOnlyDictionary<string, object?>, IReadOnlyCollection<KeyValuePair<string, object?>>, IEnumerable<KeyValuePair<string, object?>>, IEnumerableRemarks
Tags are compile-time name-value pairs used to pass contextual information from BuildAspect(IAspectBuilder<T>) to template implementations. This interface exposes tags as a dictionary while also providing access to the original source object(s) via the Source property.
Setting tags: Tags can be set in two ways:
- By passing an argument to the
tagsparameter of advice methods (e.g.,builder.Override(nameof(Template), tags: new { Key = value })) - By setting Tags at any point in BuildAspect(IAspectBuilder<T>)
When both methods are used, the tags are merged. In case of key conflicts, values from the advice method parameter take precedence.
Reading tags: In template code, access tags through meta.Tags using two approaches:
-
Dictionary access: Use
meta.Tags["key"]to read individual values. This is the typical approach when using anonymous types (e.g.,new { Key = value }). -
Source property: Use
meta.Tags.Sourceto access the original object cast to a strongly-typed class. This is useful when using a dedicated tag class instead of anonymous types.
Properties
| Name | Description |
|---|---|
| Source | Gets the original source object(s) used to set the tags. |