コード例 #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);
                }
            });
        }
コード例 #2
0
 public OptArgInfo(PropertyInfo propertyInfo, OptionalArgAttribute arg) : base(propertyInfo)
 {
     Argument = arg;
 }