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); } }); }
public OptArgInfo(PropertyInfo propertyInfo, OptionalArgAttribute arg) : base(propertyInfo) { Argument = arg; }