Skip to content

Commit 6662e18

Browse files
committed
Introduce MaybeCompatible property to ItemMetadata
The `MaybeCompatible` property attempts to determine whether a compatible or convertible member is available on a corresponding topic. This is useful as a quick heuristic for weeding out cases where compatibility is unexpected. Due to limitations of the implementation, it cannot guarantee compatibility—or incompatibility—since it doesn't know the source topic type. But, for our purposes, it should be good enough at indicating whether compatibility is likely. The will provide the foundation for #Feature #102.
1 parent 4b3a6d6 commit 6662e18

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

OnTopic/Internal/Reflection/ItemMetadata.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,36 @@ internal ItemConfiguration Configuration {
155155
/// </summary>
156156
internal bool IsConvertible { get; init; }
157157

158+
/*==========================================================================================================================
159+
| MAYBE COMPATIBLE?
160+
\-------------------------------------------------------------------------------------------------------------------------*/
161+
/// <summary>
162+
/// Determine if the item corresponds to a member on the <see cref="Topic"/> class (or derivative) associated with the
163+
/// parent <see cref="TypeAccessor"/>.
164+
/// </summary>
165+
/// <remarks>
166+
/// <para>
167+
/// The <see cref="MaybeCompatible"/> does not <i>guarantee</i> that a corresponding compatible property will be found.
168+
/// First, it cannot know what the source <see cref="Topic"/> will be, so it relies only evaluates topics who match the
169+
/// naming convention (e.g., <c>{ContentType}TopicViewModel</c> maps to <c>{ContentType}</c>), and otherwise falls back
170+
/// to <see cref="Topic"/>; if a model is mapped to a different derivative of <see cref="Topic"/>, additional matches
171+
/// may be available. Second, it evaluates whether the <see cref="Topic"/> member is of a type that can be assigned to
172+
/// the model member, or otherwise <i>converted</i>—i.e., that the <see cref="Topic"/> member is a string, and the model
173+
/// member is one of the <see cref="AttributeValueConverter.ConvertibleTypes"/>. This provides a hint for avoiding type
174+
/// checks in cases we don't expect to be compatible, while deferring to the caller to provide more sophisticated checks
175+
/// based on the actual <see cref="Topic"/>.
176+
/// </para>
177+
/// <para>
178+
/// The <see cref="MaybeCompatible"/> property must be set from the <see cref="TypeAccessor"/>, which is best positioned
179+
/// to efficiently determine the corresponding attributes. To do this, it must rely on attributes accessed via the <see
180+
/// cref="Configuration"/> property. As a result, the <see cref="MaybeCompatible"/> must be set <i>after</i> the <see
181+
/// cref="ItemMetadata"/> instance has been constructed, instead of during initialization like the other properties.
182+
/// That isn't ideal, but isn't easy to avoid without making each <see cref="ItemMetadata"/> aware of the parent <see
183+
/// cref="TypeAccessor"/>.
184+
/// </para>
185+
/// </remarks>
186+
internal bool MaybeCompatible { get; set; }
187+
158188
/*==========================================================================================================================
159189
| CUSTOM ATTRIBUTES
160190
\-------------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)