コード例 #1
0
ファイル: CommandLine.cs プロジェクト: ARLM-Attic/pass
        /// <summary>
        /// Gera uma mensagem de help do projeto
        /// </summary>
        /// <param name="mensagemErro">Mensagem de erro</param>
        /// <returns>Erro com o help</returns>
        private string GeraErro(string mensagemErro)
        {
            StringBuilder sb     = new StringBuilder();
            TextWriter    writer = new StringWriter(sb);

            writer.WriteLine(@"
{0}

USO:
    pass.exe [-Modificador] [Valor Parametro]

onde os modificadores e valores válidos são:", mensagemErro);

            Type tipo = this.GetType();

            foreach (PropertyInfo property in tipo.GetProperties())
            {
                CommandParameterAttribute cmdParamAttr = (CommandParameterAttribute)property.GetCustomAttributes(typeof(CommandParameterAttribute), false).FirstOrDefault();
                if (cmdParamAttr == null)
                {
                    continue;
                }

                DescriptionAttribute descAttribute = (DescriptionAttribute)property.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault();
                string desc = (descAttribute == null)? "[Sem descrição]" : descAttribute.Description;

                writer.WriteLine("  {0}{1}{2}", cmdParamAttr.Modifier,
                                 new string(' ', Math.Max(0, 15 - cmdParamAttr.Modifier.Length)),
                                 desc);
            }

            throw new Exception(sb.ToString());
        }
コード例 #2
0
ファイル: CommandLine.cs プロジェクト: ARLM-Attic/pass
        /// <summary>
        /// Carrega os parametros default
        /// </summary>
        private void CarregaParametrosDefault()
        {
            Type thisType = typeof(Parametros);

            foreach (PropertyInfo pInfo in thisType.GetProperties())
            {
                CommandParameterAttribute cmdParam = (CommandParameterAttribute)pInfo.GetCustomAttributes(typeof(CommandParameterAttribute), false).FirstOrDefault();
                if (cmdParam != null)
                {
                    SalvaValorPropriedade(pInfo, cmdParam.DefaultValue);
                }
            }
        }