|
| 1 | +# UNC002 : Property attribute not allowed standalone |
| 2 | +This diagnostic is reported when an attribute is detected that is a qualifier to another |
| 3 | +required attribute, but the required attribute is not present. |
| 4 | + |
| 5 | +## Example |
| 6 | +`FolderValidationAttribute` provides additional information for validation of a property. To |
| 7 | +generate source that operates correctly an additional attribute is required. For example, |
| 8 | +to specify that a Folder provided must exist already a command can apply the |
| 9 | +`FolderValidationAttribute`. However that attribute requires additional information to |
| 10 | +identify the property as an option and other behaviors. Without the constrained attribute |
| 11 | +this attribute and property it is attached to is ignored by source generation. |
| 12 | + |
| 13 | +``` C# |
| 14 | +using System.IO; |
| 15 | + |
| 16 | +using Ubiquity.NET.CommandLine.GeneratorAttributes; |
| 17 | + |
| 18 | +namespace TestNamespace; |
| 19 | + |
| 20 | +[RootCommand( Description = "Root command for tests" )] |
| 21 | +internal class testInput1 |
| 22 | +{ |
| 23 | + // This attribute triggers UNC002 - Property attribute FolderValidation is not allowed on a property independent of a qualifying attribute such as OptionAttribute. |
| 24 | + [FolderValidation( FolderValidation.CreateIfNotExist )] |
| 25 | + public required DirectoryInfo SomePath { get; init; } |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +## Fix |
| 30 | +``` C# |
| 31 | +using System.IO; |
| 32 | + |
| 33 | +using Ubiquity.NET.CommandLine.GeneratorAttributes; |
| 34 | + |
| 35 | +namespace TestNamespace; |
| 36 | + |
| 37 | +[RootCommand( Description = "Root command for tests" )] |
| 38 | +internal class testInput1 |
| 39 | +{ |
| 40 | + // Fix is to apply the attribute that indicates the property being validated |
| 41 | + [Option( "-o", Description = "Test SomePath" )] |
| 42 | + [FolderValidation( FolderValidation.CreateIfNotExist )] |
| 43 | + public required DirectoryInfo SomePath { get; init; } |
| 44 | +} |
| 45 | +``` |
0 commit comments