getDirectAnnotation<A> method
A?
getDirectAnnotation<A>()
Gets a single annotation by type, if present.
Type Parameters:
A: The annotation type to look for
Returns:
- The annotation instance of type
Aif found nullif no matching annotation exists
Example:
final deprecated = method.getDirectAnnotation<Deprecated>();
if (deprecated != null) {
print('Deprecation message: ${deprecated.message}');
}
Implementation
A? getDirectAnnotation<A>() {
checkAccess('getDirectAnnotation', DomainPermission.READ_ANNOTATIONS);
final annotations = getAllDirectAnnotations();
for (final annotation in annotations) {
if (annotation.matches<A>()) {
try {
return annotation.getInstance<A>();
} catch (_) {
return null;
}
}
}
return null;
}