Exemplo n.º 1
0
			public Argument(ArgumentAttribute attribute, FieldInfo field, ErrorReporter reporter)
			{
				this.longName = Parser.LongName(attribute, field);
				this.explicitShortName = Parser.ExplicitShortName(attribute);
				this.shortName = Parser.ShortName(attribute, field);
				this.hasHelpText = Parser.HasHelpText(attribute);
				this.helpText = Parser.HelpText(attribute, field);
				this.defaultValue = Parser.DefaultValue(attribute, field);
				this.elementType = ElementType(field);
				this.flags = Flags(attribute, field);
				this.field = field;
				this.seenValue = false;
				this.reporter = reporter;
				this.isDefault = attribute != null && attribute is DefaultArgumentAttribute;
                this.isToggle = attribute.IsToggle;

				if (IsCollection)
				{
					this.collectionValues = new ArrayList();
				}
                
				Debug.Assert(this.longName != null && this.longName != "");
				Debug.Assert(!this.isDefault || !this.ExplicitShortName);
				Debug.Assert(!IsCollection || AllowMultiple, "Collection arguments must have allow multiple");
				Debug.Assert(!Unique || IsCollection, "Unique only applicable to collection arguments");
				Debug.Assert(IsValidElementType(Type) ||
					IsCollectionType(Type));
				Debug.Assert((IsCollection && IsValidElementType(elementType)) ||
					(!IsCollection && elementType == null));
				Debug.Assert(!(this.IsRequired && this.HasDefaultValue), "Required arguments cannot have default value");
				Debug.Assert(!this.HasDefaultValue || (this.defaultValue.GetType() == field.FieldType), "Type of default value must match field type");
			}
Exemplo n.º 2
0
		private static object DefaultValue(ArgumentAttribute attribute, FieldInfo field)
		{
			return (attribute == null || !attribute.HasDefaultValue) ? null : attribute.DefaultValue;
		}
Exemplo n.º 3
0
		private static ArgumentType Flags(ArgumentAttribute attribute, FieldInfo field)
		{
			if (attribute != null)
				return attribute.Type;
			else if (IsCollectionType(field.FieldType))
				return ArgumentType.MultipleUnique;
			else
				return ArgumentType.AtMostOnce;
		}
Exemplo n.º 4
0
		private static bool ExplicitShortName(ArgumentAttribute attribute)
		{
			return (attribute != null && !attribute.DefaultShortName);
		}
Exemplo n.º 5
0
		private static bool HasHelpText(ArgumentAttribute attribute)
		{
			return (attribute != null && attribute.HasHelpText);
		}
Exemplo n.º 6
0
		private static string HelpText(ArgumentAttribute attribute, FieldInfo field)
		{
			if (attribute == null)
				return null;
			else
				return attribute.HelpText;
		}
Exemplo n.º 7
0
		private static string ShortName(ArgumentAttribute attribute, FieldInfo field)
		{
			if (attribute is DefaultArgumentAttribute)
				return null;
			if (!ExplicitShortName(attribute))
				return LongName(attribute, field).Substring(0,1);
			return attribute.ShortName;
		}
Exemplo n.º 8
0
		private static string LongName(ArgumentAttribute attribute, FieldInfo field)
		{
			return (attribute == null || attribute.DefaultLongName) ? field.Name : attribute.LongName;
		}