/// <summary> /// Resolves <see cref="CommandOptionSchema"/>. /// </summary> internal static CommandOptionSchema?TryResolve(PropertyInfo property) { CommandOptionAttribute?attribute = property.GetCustomAttribute <CommandOptionAttribute>(); if (attribute is null) { return(null); } string name = attribute.HasAutoGeneratedName ? TextUtils.ToKebabCase(property.Name) : attribute.Name !; if (attribute.Converter is Type converterType && !converterType.Implements(typeof(IBindingConverter))) { throw AttributesExceptions.InvalidConverterType(converterType); } return(new CommandOptionSchema( property, name, attribute.ShortName, attribute.FallbackVariableName, attribute.IsRequired, attribute.Description, attribute.Converter )); }
/// <summary> /// Whether command can be executed in mode provided in parameter. /// </summary> public bool CanBeExecutedInMode(Type type) { if (!KnownTypesHelpers.IsCliModeType(type)) { throw AttributesExceptions.InvalidModeType(type); } if (!HasModeRestrictions()) { return(true); } if (SupportedModes is not null && !SupportedModes !.Contains(type)) { return(false); } if (ExcludedModes is not null && ExcludedModes.Contains(type)) { return(false); } return(true); }
/// <summary> /// Resolves <see cref="CommandParameterSchema"/>. /// </summary> public static CommandParameterSchema?TryResolve(PropertyInfo property) { CommandParameterAttribute?attribute = property.GetCustomAttribute <CommandParameterAttribute>(); if (attribute is null) { return(null); } string name = attribute.HasAutoGeneratedName ? TextUtils.ToKebabCase(property.Name) : attribute.Name !; if (attribute.Converter is Type converterType && !converterType.Implements(typeof(IBindingConverter))) { throw AttributesExceptions.InvalidConverterType(converterType); } return(new CommandParameterSchema( property, attribute.Order, name, attribute.Description, attribute.Converter )); }