| Severity | Warning |
| Reported by | Metalama.Extensions.Architecture |
| Message | The type '<ReferencingType>' does not respect the naming convention set on the base class or interface '<BaseType>'. The type name should match the "<Pattern>" pattern. |
Cause
You can require all types derived from a class or interface to follow a naming convention, for instance that all implementations of IFactory end with Factory. You set this convention with one of the following:
- the DerivedTypesMustRespectNamingConventionAttribute aspect, where the pattern is a star pattern and
*matches any sequence of characters; - the DerivedTypesMustRespectRegexNamingConventionAttribute aspect, where the pattern is a regular expression;
- the DerivedTypesMustRespectNamingConvention or DerivedTypesMustRespectRegexNamingConvention extension methods in a fabric.
Metalama reports LAMA0903 on every type that derives from this base type, directly or indirectly, and whose name doesn't match the pattern. In the message, <ReferencingType> is the derived type, <BaseType> is the type on which the convention is set, and <Pattern> is the pattern.
In the following example, the RepositoryBase class requires derived types to end with Repository, but the CustomerStore class doesn't.
1using Metalama.Extensions.Architecture.Aspects;
2
3namespace Doc.LAMA0903.Error;
4
5[DerivedTypesMustRespectNamingConvention( "*Repository" )]
6public abstract class RepositoryBase { }
7
8// Warning: the name does not match the *Repository pattern.
Warning LAMA0903: The type 'CustomerStore' does not respect the naming convention set on the base class or interface 'RepositoryBase'. The type name should match the "*Repository" pattern.
9internal class CustomerStore : RepositoryBase { }
10
Resolution
Do one of the following:
- Rename the derived type so that it matches the pattern, as in the following example.
- If the type intentionally doesn't follow the convention, exclude it with the ExclusionPredicateType property of the attribute or the
exclusionsparameter of the fabric method. - If the convention is wrong, change the pattern.
1using Metalama.Extensions.Architecture.Aspects;
2
3namespace Doc.LAMA0903.Fixed;
4
5[DerivedTypesMustRespectNamingConvention( "*Repository" )]
6public abstract class RepositoryBase { }
7
8// Fixed: the class is renamed to match the *Repository pattern.
9internal class CustomerRepository : RepositoryBase { }
10