Exemple #1
0
        private void Init()
        {
            Type t = typeof(CommandArguments);

            PropertyInfo[] props = t.GetProperties();
            foreach (PropertyInfo pi in props)
            {
                ArgDescriptionAttribute          argDesc    = pi.GetCustomAttribute <ArgDescriptionAttribute>();
                IEnumerable <ArgSampleAttribute> argSamples = pi.GetCustomAttributes <ArgSampleAttribute>();

                OptionalArgAttribute optArg = pi.GetCustomAttribute <OptionalArgAttribute>();
                if (optArg != null)
                {
                    _optArgs.Add(new OptArgInfo(pi, optArg)
                    {
                        Value       = pi.GetCustomAttribute <OptionalArgValueAttribute>(),
                        Description = argDesc,
                        Samples     = argSamples
                    });
                    continue;
                }

                PositionalArgAttribute posArg = pi.GetCustomAttribute <PositionalArgAttribute>();
                if (posArg != null)
                {
                    _posArgs.Add(new PosArgInfo(pi, posArg)
                    {
                        Description = argDesc,
                        Samples     = argSamples
                    });
                    continue;
                }
            }

            _posArgs.Sort((x, y) =>
            {
                if (x == null && y == null)
                {
                    return(0);
                }
                else if (x == null)
                {
                    return(-1);
                }
                else if (y == null)
                {
                    return(1);
                }
                else
                {
                    return(x.Argument.Position - y.Argument.Position);
                }
            });
        }
Exemple #2
0
 public PosArgInfo(PropertyInfo propertyInfo, PositionalArgAttribute arg) : base(propertyInfo)
 {
     Argument = arg;
 }