Beispiel #1
0
 // Methods
 public OptionList(Options optionBundle)
 {
     this.optionBundle = null;
     this.appTitle = "Add a [assembly: AssemblyTitle(\"Here goes the application name\")] to your assembly";
     this.appCopyright = "Add a [assembly: AssemblyCopyright(\"(c)200n Here goes the copyright holder name\")] to your assembly";
     this.appDescription = "Add a [assembly: AssemblyDescription(\"Here goes the short description\")] to your assembly";
     this.appAboutDetails = "Add a [assembly: Mono.About(\"Here goes the short about details\")] to your assembly";
     this.appUsageComplement = "Add a [assembly: Mono.UsageComplement(\"Here goes the usage clause complement\")] to your assembly";
     this.list = new ArrayList();
     this.arguments = new ArrayList();
     this.argumentsTail = new ArrayList();
     this.argumentProcessor = null;
     this.HasSecondLevelHelp = false;
     this.bannerAlreadyShown = false;
     this.Initialize(optionBundle);
 }
Beispiel #2
0
		public OptionList(Options optionBundle)
		{
			if (optionBundle == null)
				throw new ArgumentNullException("optionBundle");

			Type optionsType = optionBundle.GetType();
			this.optionBundle = optionBundle;
			parsingMode = optionBundle.ParsingMode;
			breakSingleDashManyLettersIntoManyOptions = optionBundle.BreakSingleDashManyLettersIntoManyOptions;
			endOptionProcessingWithDoubleDash = optionBundle.EndOptionProcessingWithDoubleDash;
			ReportError = optionBundle.ReportError;

			ExtractEntryAssemblyInfo(optionsType);

			foreach(MemberInfo mi in optionsType.GetMembers())
			{
				object[] attribs = mi.GetCustomAttributes(typeof(KillOptionAttribute), true);
				if (attribs == null || attribs.Length == 0)
				{
					attribs = mi.GetCustomAttributes(typeof(OptionAttribute), true);
					if (attribs != null && attribs.Length > 0)
					{
						OptionDetails option = new OptionDetails(mi, (OptionAttribute) attribs[0], optionBundle);
						list.Add(option);
						HasSecondLevelHelp = HasSecondLevelHelp || option.SecondLevelHelp;
					}
					else if (mi.DeclaringType == mi.ReflectedType)
					{
						// not inherited
						attribs = mi.GetCustomAttributes(typeof(ArgumentProcessorAttribute), true);
						if (attribs != null && attribs.Length > 0)
							AddArgumentProcessor(mi);
					}
				}
			}

			if (argumentProcessor == null) // try to find an inherited one
				foreach(MemberInfo mi in optionsType.GetMembers())
					if (mi.DeclaringType != mi.ReflectedType)
					{
						// inherited
						object[] attribs = mi.GetCustomAttributes(typeof(ArgumentProcessorAttribute), true);
						if (attribs != null && attribs.Length > 0)
							AddArgumentProcessor(mi);
					}
		}
		public OptionDetails(MemberInfo memberInfo, OptionAttribute option, Options optionBundle)
		{
			this.ShortForm = ("" + option.ShortForm).Trim();
			if (option.LongForm == null)
				this.LongForm = string.Empty;
			else
				this.LongForm = (option.LongForm == string.Empty)? memberInfo.Name:option.LongForm;
			this.AlternateForm = option.AlternateForm;
			this.ShortDescription = ExtractParamName(option.ShortDescription);
			this.Occurs = 0;
			this.OptionBundle = optionBundle; 
			this.BooleanOption = false;
			this.MemberInfo = memberInfo;
			this.NeedsParameter = false;
			this.Values = null;
			this.MaxOccurs = 1;
			this.VBCStyleBoolean = option.VBCStyleBoolean;
			this.SecondLevelHelp = option.SecondLevelHelp;
			this.Hidden = false; // TODO: check other attributes
			
			this.ParameterType = TypeOfMember(memberInfo);

			if (this.ParameterType != null)
			{
				if (this.ParameterType.FullName != "System.Boolean")
				{
					if (this.LongForm.IndexOf(':') >= 0)
						throw new InvalidOperationException("Options with an embedded colon (':') in their visible name must be boolean!!! [" + 
									this.MemberInfo.ToString() + " isn't]");
				
					this.NeedsParameter = true;

					if (option.MaxOccurs != 1)
					{
						if (this.ParameterType.IsArray)
						{
							this.Values = new ArrayList();
							this.MaxOccurs = option.MaxOccurs;
						}
						else
						{
							if (this.MemberInfo is MethodInfo || this.MemberInfo is PropertyInfo)
								this.MaxOccurs = option.MaxOccurs;
							else
								throw new InvalidOperationException("MaxOccurs set to non default value (" + option.MaxOccurs + ") for a [" + 
											this.MemberInfo.ToString() + "] option");
						}
					}
				}
				else
				{
					this.BooleanOption = true;
					if (option.MaxOccurs != 1)
					{			
						if (this.MemberInfo is MethodInfo || this.MemberInfo is PropertyInfo)
							this.MaxOccurs = option.MaxOccurs;
						else
							throw new InvalidOperationException("MaxOccurs set to non default value (" + option.MaxOccurs + ") for a [" + 
										this.MemberInfo.ToString() + "] option");
					}
				}
			}
		}
Beispiel #4
0
 private void Initialize(Options optionBundle)
 {
     if (optionBundle == null)
     {
         throw new ArgumentNullException("optionBundle");
     }
     this.entry = Assembly.GetEntryAssembly();
     this.appExeName = this.entry.GetName().Name;
     this.appVersion = this.entry.GetName().Version.ToString();
     this.optionBundle = optionBundle;
     this.parsingMode = optionBundle.ParsingMode;
     this.breakSingleDashManyLettersIntoManyOptions = optionBundle.BreakSingleDashManyLettersIntoManyOptions;
     this.endOptionProcessingWithDoubleDash = optionBundle.EndOptionProcessingWithDoubleDash;
     this.GetAssemblyAttributeValue(typeof(AssemblyTitleAttribute), "Title", ref this.appTitle);
     this.GetAssemblyAttributeValue(typeof(AssemblyCopyrightAttribute), "Copyright", ref this.appCopyright);
     this.GetAssemblyAttributeValue(typeof(AssemblyDescriptionAttribute), "Description", ref this.appDescription);
     this.GetAssemblyAttributeValue(typeof(AboutAttribute), ref this.appAboutDetails);
     this.GetAssemblyAttributeValue(typeof(UsageComplementAttribute), ref this.appUsageComplement);
     this.appAuthors = this.GetAssemblyAttributeStrings(typeof(AuthorAttribute));
     if (this.appAuthors.Length == 0)
     {
         this.appAuthors = new string[] { "Add one or more [assembly: Mono.GetOptions.Author(\"Here goes the author name\")] to your assembly" } ;
     }
     MemberInfo[] infoArray1 = optionBundle.GetType().GetMembers();
     for (int num1 = 0; num1 < infoArray1.Length; num1++)
     {
         MemberInfo info1 = infoArray1[num1];
         object[] objArray1 = info1.GetCustomAttributes(typeof(OptionAttribute), true);
         if ((objArray1 != null) && (objArray1.Length > 0))
         {
             OptionDetails details1 = new OptionDetails(info1, (OptionAttribute) objArray1[0], optionBundle);
             this.list.Add(details1);
             this.HasSecondLevelHelp = this.HasSecondLevelHelp || details1.SecondLevelHelp;
         }
         else
         {
             objArray1 = info1.GetCustomAttributes(typeof(ArgumentProcessorAttribute), true);
             if ((objArray1 != null) && (objArray1.Length > 0))
             {
                 this.AddArgumentProcessor(info1);
             }
         }
     }
 }
 public OptionDetails(System.Reflection.MemberInfo memberInfo, OptionAttribute option, Options optionBundle)
 {
     this.paramName = null;
     this.optionHelp = null;
     this.ShortForm = ("" + option.ShortForm).Trim();
     if (option.LongForm == null)
     {
         this.LongForm = string.Empty;
     }
     else
     {
         this.LongForm = (option.LongForm != string.Empty) ? option.LongForm : memberInfo.Name;
     }
     this.AlternateForm = option.AlternateForm;
     this.ShortDescription = this.ExtractParamName(option.ShortDescription);
     this.Occurs = 0;
     this.OptionBundle = optionBundle;
     this.BooleanOption = false;
     this.MemberInfo = memberInfo;
     this.NeedsParameter = false;
     this.Values = null;
     this.MaxOccurs = 1;
     this.VBCStyleBoolean = option.VBCStyleBoolean;
     this.SecondLevelHelp = option.SecondLevelHelp;
     this.ParameterType = OptionDetails.TypeOfMember(memberInfo);
     if (this.ParameterType != null)
     {
         if (this.ParameterType.FullName != "System.Boolean")
         {
             if (this.LongForm.IndexOf(':') >= 0)
             {
                 throw new InvalidOperationException("Options with an embedded colon (':') in their visible name must be boolean!!! [" + this.MemberInfo.ToString() + " isn't]");
             }
             this.NeedsParameter = true;
             if (option.MaxOccurs == 1)
             {
                 return;
             }
             if (this.ParameterType.IsArray)
             {
                 this.Values = new ArrayList();
                 this.MaxOccurs = option.MaxOccurs;
                 return;
             }
             if ((this.MemberInfo is MethodInfo) || (this.MemberInfo is PropertyInfo))
             {
                 this.MaxOccurs = option.MaxOccurs;
                 return;
             }
             object[] objArray1 = new object[] { "MaxOccurs set to non default value (", option.MaxOccurs, ") for a [", this.MemberInfo.ToString(), "] option" } ;
             throw new InvalidOperationException(string.Concat(objArray1));
         }
         this.BooleanOption = true;
         if (option.MaxOccurs != 1)
         {
             if ((this.MemberInfo is MethodInfo) || (this.MemberInfo is PropertyInfo))
             {
                 this.MaxOccurs = option.MaxOccurs;
             }
             else
             {
                 object[] objArray2 = new object[] { "MaxOccurs set to non default value (", option.MaxOccurs, ") for a [", this.MemberInfo.ToString(), "] option" } ;
                 throw new InvalidOperationException(string.Concat(objArray2));
             }
         }
     }
 }