Closed carstencodes closed 9 months ago
If a developer has written [HandleCommand("foo", Description="Do the bar thing")]
and then needs to make the description localisable, how would they change the code?
We're currently using CommandLineParser in most of our Projects. They solve it as follows:
Adding the HelpText will use the Text supplied. If ResourceType is set, than it will be used as the HelpText Resource Provider:
[HandleCommand("foo", Description=nameof(Resources.SR_FooCommandDescription), DescriptionResource=typeof(Resources))]
I would also prefer using System.Component.DescriptionAttribute, but as far as I am concerned, it is not localizable either, is it?
What do you think?
Most equivalent work is also present in System.ComponentModel
and System.ComponentModel.DataAnnotations
. It would be good to support it this way.
Please note, that I am also willing to contribute the implementation for this, but I won't create an implementation and add much effort into it, if the PR will be close because this is not wanted or even added to the scope by the maintainers.
DescriptionAttribute itself is not localizable, but derived classes can load the description from resources, like here: https://github.com/dotnet/runtime/blob/bf5e279d9239bfef5bb1b8d6212f1b971c434606/src/libraries/System.ComponentModel.TypeConverter/src/System/Timers/TimersDescriptionAttribute.cs#L24
I suppose a source generator could support that by translating [CustomDescription("ResourceKey")]
to new CustomDescriptionAttribute("ResourceKey").Description
if it detects that CustomDescriptionAttribute is based on DescriptionAttribute.
Just as an FYI, there is already a 3rd-party project that is trying to do what you seek: https://github.com/dotnet/command-line-api/discussions/2310 (based on the System.CommandLine version available on the public nuget.org and not on the newer System.CommandLine code base as present in the repository here, as it seems). It supports code generation but it seems to lack localization features as of now.
Awesome!
Hello,
as I am a huge fan of Don't Repeat Yourself.
If I am using the NamingConventionBinder, I do something like this:
with
In order to minimize shattering, I would suggest doing the following:
using
At that point, I would like to have something like:
where a source generator will create an implementation for
What do you think? Would this be a good feature to add to this project?
If not, feel free to close this issue.