Note
You can only use nameof if the name of the argument matches the name of the
property. Be careful if you have explicit names or are using a NameTransform.
public class RequiresAnyAttribute : ClassValidationAttribute
Public Class RequiresAnyAttribute
Inherits ClassValidationAttribute
Dim instance As RequiresAnyAttribute
public ref class RequiresAnyAttribute : public ClassValidationAttribute
This is a class validator, which should be applied to the class that defines arguments, not to a specific argument.
Use this attribute if you have multiple arguments, only one of which needs to be supplied at a time.
This attribute is useful when combined with the ProhibitsAttribute attribute. If you have two mutually exclusive attribute, you cannot mark either of them as required. For example, given arguments A and B, if B prohibits A but A is required, then B can never be used.
Instead, you can use the RequiresAnyAttribute attribute to indicate that the user must supply either A or B, and the ProhibitsAttribute attribute to indicate that they cannot supply both at once.
[RequiresAny(nameof(Address), nameof(Path))]
class Arguments
{
[CommandLineArgument]
public Uri Address { get; set; }
[CommandLineArgument]
[Prohibits(nameof(Address))]
public string Path { get; set; }
}
The names of the arguments are not validated when the attribute is created. If one of the specified arguments does not exist, an exception is thrown during validation.
RequiresAnyAttribute(String) | Initializes a new instance of the RequiresAnyAttribute class. |
RequiresAnyAttribute(String, String) | Initializes a new instance of the RequiresAnyAttribute class. |
Arguments | Gets the names of the arguments, one of which must be supplied on the command line. |
ErrorCategory |
Gets the error category used for the CommandLineArgumentException when
validation fails.
(Overrides ClassValidationAttributeErrorCategory) |
IncludeInUsageHelp | Gets or sets a value that indicates whether this validator's help should be included in the usage help. |
TypeId | When implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute) |
Equals | Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute) |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) |
GetArguments | Resolves the argument names in the Arguments property to their actual CommandLineArgument instances. |
GetErrorMessage |
Gets the error message to display if validation failed.
(Overrides ClassValidationAttributeGetErrorMessage(CommandLineParser)) |
GetHashCode | Returns the hash code for this instance. (Inherited from Attribute) |
GetType | Gets the Type of the current instance. (Inherited from Object) |
GetUsageHelp |
Gets the usage help message for this validator.
(Overrides ClassValidationAttributeGetUsageHelp(CommandLineParser)) |
IsDefaultAttribute | When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute) |
IsValid |
Determines if at least one of the arguments in the Arguments property was
supplied on the command line.
(Overrides ClassValidationAttributeIsValid(CommandLineParser)) |
Match | When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute) |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) |
ToString | Returns a string that represents the current object. (Inherited from Object) |
Validate |
Validates the argument value, and throws an exception if validation failed.
(Inherited from ClassValidationAttribute) |