public ArgumentInfo(CISimpleArgumentAttribute argument, int index) { if (index < 0) { throw new ArgumentException("The index must be greater or equal to zero."); } if (argument == null) { throw new ArgumentNullException("argument"); } SimpleArgument = argument; SimpleArgumentIndex = index; Children = new ArgumentInfoCollection(this); }
private void RegisterAttributesFromClassProperties(Type type, ArgumentInfoCollection argumentsInfo) { PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); int simpleArgumentIndex = 0; foreach (PropertyInfo pinfo in properties) { ArgumentInfo ainfo = null; CISimpleArgumentAttribute csaa = pinfo.GetCustomAttribute <CISimpleArgumentAttribute>(); if (csaa == null) { CINamedArgumentAttribute cnaa = pinfo.GetCustomAttribute <CINamedArgumentAttribute>(); if (cnaa == null) { continue; // Not a field associated with a console argument } if (cnaa.Names.Length == 0) { throw new InvalidArgumentDefinitionException(string.Format("No argument name associated with the property {0}.", pinfo.Name)); } // If the collection already contains one the of arguments specified in the current AppArgumentAttribute if (argumentsInfo.Contains(cnaa.Names)) { throw new InvalidArgumentDefinitionException(string.Format("One of the argument specified with the property {0} has been already registered.", pinfo.Name)); } ainfo = new ArgumentInfo(cnaa); } else { ainfo = new ArgumentInfo(csaa, simpleArgumentIndex++); } ainfo.PInfo = pinfo; ainfo.MandatoryArgument = pinfo.GetCustomAttribute <CIMandatoryArgumentAttribute>(); ainfo.GroupedMandatoryArgument = pinfo.GetCustomAttribute <CIGroupedMandatoryArgumentAttribute>(); ainfo.ArgumentBoundary = pinfo.GetCustomAttribute <CIArgumentBoundaryAttribute>(); ainfo.ArgumentValueLength = pinfo.GetCustomAttribute <CIArgumentValueLengthAttribute>(); ainfo.ArgumentFormat = pinfo.GetCustomAttribute <CIArgumentFormatAttribute>(); ainfo.Job = pinfo.GetCustomAttribute <CIJobAttribute>(); ainfo.FileContent = pinfo.GetCustomAttribute <CIFileContentAttribute>(); ainfo.Password = pinfo.GetCustomAttribute <CIPasswordAttribute>(); ainfo.Exclusive = pinfo.GetCustomAttribute <CIExclusiveArgumentAttribute>(); if (pinfo.PropertyType.IsUserType()) { ainfo.UserType = true; ainfo.UserTypeInstance = Activator.CreateInstance(pinfo.PropertyType); ArgumentInfoCollection childrenInfo = new ArgumentInfoCollection(); RegisterAttributesFromClassProperties(pinfo.PropertyType, childrenInfo); ainfo.Children.AddRange(childrenInfo); } if (ainfo.NamedArgument != null && this.argumentsInfo.DeepContains(ainfo.Name)) { throw new DuplicateArgumentDefinitionException(ainfo.Name); } argumentsInfo.Add(ainfo); } }