示例#1
0
        protected SwitchesDefBase()
        {
            this.Args = new SwitchCollection(this);

            foreach (PropertyInfo prop in this.GetType().GetProperties())
            {
                // ignore ExtraArguments and properties without setters
                if (prop.Name == "ExtraArguments" || prop.GetSetMethod() == null)
                {
                    continue;
                }

                // check for SwitchDef attribute
                var attr = prop.GetAttribute <SwitchDefAttribute>();
                if (attr != null)
                {
                    if (prop.PropertyType == typeof(bool) || prop.PropertyType == typeof(string) ||
                        prop.PropertyType == typeof(uint?) || prop.PropertyType.Implements <IList <string> >())
                    {
                        var arg = new SwitchInfo(prop);
                        if (attr.ShortSwitch != null)
                        {
                            arg.ShortSwitch = attr.ShortSwitch;
                        }
                        if (attr.LongSwitch != null)
                        {
                            arg.LongSwitch = attr.LongSwitch;
                        }
                        arg.Description      = attr.Description;
                        arg.ValueDescription = attr.ValueDescription;

                        if (prop.HasAttribute <SwitchHiddenAttribute>())
                        {
                            arg.Hidden = true;
                        }

                        Args.AddSwitch(arg);
                    }
                    else
                    {
                        throw new ArgumentException(String.Format("Argument {0} is marked as a commandline arg, but is not a supported type", prop.Name));
                    }
                }
            }
        }
		protected SwitchesDefBase()
		{
			this.Args = new SwitchCollection(this);

			foreach (PropertyInfo prop in this.GetType().GetProperties())
			{
				// ignore ExtraArguments and properties without setters
				if (prop.Name == "ExtraArguments" || prop.GetSetMethod() == null)
					continue;

				// check for SwitchDef attribute
				var attr = prop.GetAttribute<SwitchDefAttribute>();
				if (attr != null)
				{
					if (prop.PropertyType == typeof(bool) || prop.PropertyType == typeof(string) ||
							prop.PropertyType == typeof(uint?) || prop.PropertyType.Implements<IList<string>>())
					{
						var arg = new SwitchInfo(prop);
						if (attr.ShortSwitch != null)
							arg.ShortSwitch = attr.ShortSwitch;
						if (attr.LongSwitch != null)
							arg.LongSwitch = attr.LongSwitch;
						arg.Description = attr.Description;
						arg.ValueDescription = attr.ValueDescription;

						if (prop.HasAttribute<SwitchHiddenAttribute>())
							arg.Hidden = true;

						Args.AddSwitch(arg);
					}
					else
					{
						throw new ArgumentException(String.Format("Argument {0} is marked as a commandline arg, but is not a supported type", prop.Name));
					}
				}
			}
		}