commandlineparser / commandlineparser/commandline

Allow runtime attribute values via static methods

Abierto
#191 3 comentarios 6 reacciones 0 asignados Ver en GitHub
feature request
Lenguaje dominante
C#
Estrellas
4.8k
Forks
478
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Attribute values are limited to compile-time constant [attribute parameter types](https://github.com/dotnet/csharplang/blob/master/spec/attributes.md#attribute-parameter-types). This can be limiting when values need to be evaluated at runtime. For example, I might want to take my help text or license from some file, or I might want a non-constant default value, or I might want [dynamic options](https://github.com/commandlineparser/commandline/issues/9), etc.

One way around this would be a string pointer to a property/method which would supply the actual value:

```cs
class MyOptions
{
[Option('f', "foo", HelpTextProperty = nameof(FooHelpText), Default = nameof(FooDefault))]
public int Foo {get; set;}

private string FooHelpText {get { return File.ReadAllText("foo.txt"); } }
private int FooDefault {get { return Math.Pow(2,5); } }
}
```

Of course type validation would be performed (Default should have an assignable type to the property type, HelpTest should be a string, etc) for all such pointers (regardless of whether they are actually invoked, to fail fast in case of type inconsistency)

This is just one example, I believe this could be useful for many other attribute properties. To explicitly name the attributes currently defined in the library:
- `AssemblyLicenseAttribute` (don't really understand the multiple line thing BTW, why not just pass the full string including newlines)
- `AssemblyUsageAttribute` (same comment)
- `OptionAttribute`
- `ValueAttribute`
- `UsageAttribute`
- `VerbAttribute`

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Comienza revisando las definiciones indicadas de AssemblyLicenseAttribute, AssemblyUsageAttribute, OptionAttribute, ValueAttribute, UsageAttribute y VerbAttribute. Rastrea cómo se consumen los valores de sus atributos y, a continuación, determina el alcance de la resolución en tiempo de ejecución de métodos o propiedades y de la validación de tipos en esos atributos. El trabajo estará terminado cuando incluya un diseño decidido y cobertura para los valores de tiempo de ejecución admitidos.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
csharp
Área
cli
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.