Files
ArgumentsToolkit/ArgumentsToolkit.Help/Collectors/HelpCollector.cs

37 lines
1.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Reflection;
namespace ArgumentsToolkit.Help;
/// <summary>
/// Сборщик информации о параметрах из модели Options.
/// </summary>
public static class HelpCollector
{
/// <summary>
/// Собирает метаданные о параметрах из указанной модели Options.
/// </summary>
public static HelpModel Collect<T>()
{
var model = new HelpModel();
var props = typeof(T).GetProperties();
foreach (var prop in props)
{
var opt = prop.GetCustomAttribute<OptionAttribute>();
if (opt == null) continue;
model.Entries.Add(new HelpEntry
{
Name = opt.Name,
ShortName = opt.ShortName,
Description = opt.Description,
TypeName = prop.PropertyType.Name,
Required = opt.Required,
DefaultValue = opt.DefaultValue
});
}
return model;
}
}