Exemple #1
0
 public Argument(ArgumentAttribute attribute, FieldInfo field, ErrorReporter reporter)
 {
     longName = Parser.LongName(attribute, field);
     explicitShortName = Parser.ExplicitShortName(attribute);
     shortName = Parser.ShortName(attribute, field);
     hasHelpText = Parser.HasHelpText(attribute);
     helpText = Parser.HelpText(attribute, field);
     defaultValue = Parser.DefaultValue(attribute, field);
     elementType = ElementType(field);
     flags = Flags(attribute, field);
     this.field = field;
     seenValue = false;
     this.reporter = reporter;
     isDefault = (attribute != null && attribute is DefaultArgumentAttribute);
     if (IsCollection)
     {
         collectionValues = new ArrayList();
     }
     Debug.Assert(longName != null && longName != "");
     Debug.Assert(!isDefault || !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(!IsRequired || !HasDefaultValue, "Required arguments cannot have default value");
     Debug.Assert(!HasDefaultValue || defaultValue.GetType() == field.FieldType, "Type of default value must match field type");
 }
Exemple #2
0
 static string LongName(ArgumentAttribute attribute, FieldInfo field)
 {
     return (attribute == null || attribute.DefaultLongName) ? field.Name : attribute.LongName;
 }
Exemple #3
0
 static string ShortName(ArgumentAttribute attribute, FieldInfo field)
 {
     string result;
     if (attribute is DefaultArgumentAttribute)
     {
         result = null;
     }
     else
     {
         if (!ExplicitShortName(attribute))
         {
             result = LongName(attribute, field).Substring(0, 1);
         }
         else
         {
             result = attribute.ShortName;
         }
     }
     return result;
 }
Exemple #4
0
 static string HelpText(ArgumentAttribute attribute, FieldInfo field)
 {
     string result;
     if (attribute == null)
     {
         result = null;
     }
     else
     {
         result = attribute.HelpText;
     }
     return result;
 }
Exemple #5
0
 static bool HasHelpText(ArgumentAttribute attribute)
 {
     return attribute != null && attribute.HasHelpText;
 }
Exemple #6
0
 static ArgumentType Flags(ArgumentAttribute attribute, FieldInfo field)
 {
     ArgumentType result;
     if (attribute != null)
     {
         result = attribute.Type;
     }
     else
     {
         if (IsCollectionType(field.FieldType))
         {
             result = ArgumentType.MultipleUnique;
         }
         else
         {
             result = ArgumentType.AtMostOnce;
         }
     }
     return result;
 }
Exemple #7
0
 static bool ExplicitShortName(ArgumentAttribute attribute)
 {
     return attribute != null && !attribute.DefaultShortName;
 }
Exemple #8
0
 static object DefaultValue(ArgumentAttribute attribute, FieldInfo field)
 {
     return (attribute == null || !attribute.HasDefaultValue) ? null : attribute.DefaultValue;
 }