// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
using System;
namespace CommandLine
{
///
/// Models a base attribute to define command line syntax.
///
public abstract class BaseAttribute : Attribute
{
private int min;
private int max;
private object @default;
private Infrastructure.LocalizableAttributeProperty helpText;
private string metaValue;
private Type resourceType;
///
/// Initializes a new instance of the class.
///
protected internal BaseAttribute()
{
min = -1;
max = -1;
helpText = new Infrastructure.LocalizableAttributeProperty(nameof(HelpText));
metaValue = string.Empty;
resourceType = null;
}
///
/// Gets or sets a value indicating whether a command line option is required.
///
public bool Required
{
get;
set;
}
///
/// When applied to properties defines
/// the lower range of items.
///
/// If not set, no lower range is enforced.
public int Min
{
get { return min; }
set
{
if (value < 0)
{
throw new ArgumentNullException("value");
}
min = value;
}
}
///
/// When applied to properties defines
/// the upper range of items.
///
/// If not set, no upper range is enforced.
public int Max
{
get { return max; }
set
{
if (value < 0)
{
throw new ArgumentNullException("value");
}
max = value;
}
}
///
/// Gets or sets mapped property default value.
///
public object Default
{
get { return @default; }
set
{
@default = value;
}
}
///
/// Gets or sets a short description of this command line option. Usually a sentence summary.
///
public string HelpText
{
get => helpText.Value??string.Empty;
set => helpText.Value = value ?? throw new ArgumentNullException("value");
}
///
/// Gets or sets mapped property meta value. Usually an uppercase hint of required value type.
///
public string MetaValue
{
get { return metaValue; }
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
metaValue = value;
}
}
///
/// Gets or sets a value indicating whether a command line option is visible in the help text.
///
public bool Hidden
{
get;
set;
}
///
/// Gets or sets the that contains the resources for .
///
public Type ResourceType
{
get { return resourceType; }
set
{
resourceType =
helpText.ResourceType = value;
}
}
}
}