-
Notifications
You must be signed in to change notification settings - Fork 0
Allow multiple [CleanUtility(...)] annotations per class
#88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| using System.Collections.Generic; | ||
| using TryAtSoftware.Extensions.Collections; | ||
|
|
||
| [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] | ||
| [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] | ||
|
||
| public class CleanUtilityAttribute : Attribute | ||
| { | ||
| public string Name { get; } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,16 +67,16 @@ private static void RegisterUtilitiesFromAssembly(IAssemblyInfo assemblyInfo, Li | |
| { | ||
| if (type.IsAbstract) continue; | ||
|
|
||
| var initializationUtilityAttributes = type.GetCustomAttributes(typeof(CleanUtilityAttribute)).ToArray(); | ||
| if (initializationUtilityAttributes.Length == 0) continue; | ||
| var cleanUtilityAttributes = type.GetCustomAttributes(typeof(CleanUtilityAttribute)).ToArray(); | ||
|
||
| if (cleanUtilityAttributes.Length == 0) continue; | ||
|
|
||
| var decoratedType = new DecoratedType(type); | ||
| var externalDemands = decoratedType.ExtractDemands<ExternalDemandsAttribute>(); | ||
| var internalDemands = decoratedType.ExtractDemands<InternalDemandsAttribute>(); | ||
| var outerDemands = decoratedType.ExtractDemands<OuterDemandsAttribute>(); | ||
| var requirements = ExtractRequirements(type); | ||
|
|
||
| foreach (var utilityAttribute in initializationUtilityAttributes.OrEmptyIfNull().IgnoreNullValues()) | ||
| foreach (var utilityAttribute in cleanUtilityAttributes.OrEmptyIfNull().IgnoreNullValues()) | ||
| { | ||
| var categoryArgument = utilityAttribute.GetNamedArgument<string>(nameof(CleanUtilityAttribute.Category)); | ||
| var nameArgument = utilityAttribute.GetNamedArgument<string>(nameof(CleanUtilityAttribute.Name)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While allowing multiple CleanUtility attributes on the same class is technically supported by the registration code, there's a critical constraint that needs to be documented: each attribute on the same class must have a unique combination of Category and Name. The utility ID is computed as "c:{Category}|n:{Name}" (see ICleanUtilityDescriptor interface), and duplicate IDs will cause a runtime exception during registration (see CleanTestAssemblyData constructor line 33: "Two clean utilities with the same identifier cannot co-exist."). Consider adding this constraint to the attribute's documentation or implementing validation to provide a clearer error message when duplicate combinations are detected.