Skip to content

Commit aac3e97

Browse files
committed
Added AttributeDescriptor fallback logic for DefaultTopicLookupService
This corresponds to a similar update for `DynamicTopicLookupService` (cd9e540).
1 parent 5eb7de9 commit aac3e97

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

OnTopic/Lookup/DefaultTopicLookupService.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,30 @@ public DefaultTopicLookupService(IEnumerable<Type>? types = null, Type? defaultT
4242

4343
}
4444

45+
/*==========================================================================================================================
46+
| METHOD: LOOKUP
47+
\-------------------------------------------------------------------------------------------------------------------------*/
48+
/// <inheritdoc/>
49+
/// <remarks>
50+
/// The <see cref="DefaultTopicLookupService"/> version of <see cref="Lookup(String)"/> will automatically fall back to
51+
/// <see cref="AttributeDescriptor"/> if the <paramref name="typeName"/> ends with <c>AttributeDescriptor</c>, but a
52+
/// <see cref="AttributeDescriptor"/> with the specified name cannot be found. This accounts for the fact that strongly
53+
/// typed <see cref="AttributeDescriptor"/> classes are expected to be in external plugins which are not statically
54+
/// registered with the <see cref="DefaultTopicLookupService"/>. In that case, the base <see cref="AttributeDescriptor"/>
55+
/// class will provide access to the attributes needed by most applications, including the core OnTopic library.
56+
/// </remarks>
57+
public override Type? Lookup(string typeName) {
58+
if (typeName is null) {
59+
return DefaultType;
60+
}
61+
else if (Contains(typeName)) {
62+
return base.Lookup(typeName);
63+
}
64+
else if (typeName.EndsWith("AttributeDescriptor", StringComparison.OrdinalIgnoreCase)) {
65+
return typeof(AttributeDescriptor);
66+
}
67+
return DefaultType;
68+
}
69+
4570
} //Class
4671
} //Namespace

0 commit comments

Comments
 (0)