Пример #1
0
        public static string GetDescription(this GetGamesOptions opts)
        {
            StringBuilder sb = new StringBuilder();
            var           descriptiveOptions = opts.GetType().GetProperties().Where(x => Attribute.IsDefined(x, typeof(DescriptionAttribute)) && Attribute.IsDefined(x, typeof(OptionAttribute)));

            foreach (var opt in descriptiveOptions)
            {
                var desc = opt.GetPropertyDescription(opts);
                var val  = opt.GetPropertyValue(opts);
                sb.AppendLine($"{desc}: {val}");
            }
            return(sb.ToString());
        }
Пример #2
0
        public static string CreateQueryString(this GetGamesOptions opts)
        {
            var qsOptions = new Dictionary <string, string>();

            foreach (var pInfo in opts.GetType().GetProperties().Where(p => p.GetCustomAttributes(typeof(QueryStringDescriptionAttribute), false).Any()))
            {
                var value      = pInfo.GetValue(opts);
                var type       = pInfo.PropertyType;
                var defaultVal = type.GetDefault();
                if (!AreEqual(defaultVal, value, type))
                {
                    var attr = (QueryStringDescriptionAttribute[])pInfo.GetCustomAttributes(typeof(QueryStringDescriptionAttribute), false);
                    if (attr.Any())
                    {
                        qsOptions.Add(attr.First().QueryStringKey, value.ToString());
                    }
                }
            }

            return(qsOptions.CreateQueryString());
        }