Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

296
Vistas
Convertir el ejemplo de introducción de Spectre.Console a F#

Me gustaría usar Spectre.Console en una aplicación de consola F#. Estoy tratando de convertir el ejemplo de Introducción de C# a F#. A continuación se muestra mi intento:

 open System open Spectre.Console.Cli type AddSettings() = inherit CommandSettings() [<CommandArgument(0, "[PROJECT]")>] member val Project = "" with get, set type AddPackageSettings() = inherit AddSettings() [<CommandArgument(0, "<PACKAGE_NAME>")>] member val PackageName = "" with get, set [<CommandOption("-v|--version <VERSION>")>] member val Version = "" with get, set type AddReferenceSettings() = inherit AddSettings() [<CommandArgument(0, "<PROJECT_REFERENCE>")>] member val ProjectReference = "" with get, set type AddPackageCommand() = inherit Command<AddPackageSettings>() override _.Execute (context, settings) = 0 type AddReferenceCommand() = inherit Command<AddReferenceSettings>() override _.Execute(context, settings) = 0 // Define a function to construct a message to print let from whom = sprintf "from %s" whom [<EntryPoint>] let main argv = let message = from "F#" // Call the function let app = CommandApp() app.Configure(fun config -> config.AddBranch<AddSettings>("add", fun add -> add.AddCommand<AddPackageCommand>("package") add.AddCommand<AddReferenceCommand>("reference") ) ) app.Run(argv)

Desafortunadamente, recibo el siguiente error del compilador:

 The type 'AddPackageCommand' is not compatible with the type 'ICommandLimiter<AddSettings>'

El tipo 'AddPackageCommand' no es compatible con el tipo 'ICommandLimiter'

Gracias por cualquier ayuda.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Así es como resolví ese problema:

  1. Agregue explícitamente interface ICommandLimiter<AddSettings> a las subclases de Command que usan la herencia en la configuración de AddSettings .
  2. Cambie la llamada AddBranch para inferir el argumento genérico simplemente anotando el tipo de IConfigurator : config.AddBranch("add", fun (add: IConfigurator<AddSettings>) -> ... .
 open System open Spectre.Console.Cli type AddSettings() = inherit CommandSettings() [<CommandArgument(0, "[PROJECT]")>] member val Project = "" with get, set type AddPackageSettings() = inherit AddSettings() [<CommandArgument(0, "<PACKAGE_NAME>")>] member val PackageName = "" with get, set [<CommandOption("-v|--version <VERSION>")>] member val Version = "" with get, set type AddReferenceSettings() = inherit AddSettings() [<CommandArgument(0, "<PROJECT_REFERENCE>")>] member val ProjectReference = "" with get, set type AddPackageCommand() = inherit Command<AddPackageSettings>() interface ICommandLimiter<AddSettings> override _.Execute (context, settings) = 0 type AddReferenceCommand() = inherit Command<AddReferenceSettings>() interface ICommandLimiter<AddSettings> override _.Execute(context, settings) = 0 // Define a function to construct a message to print let from whom = sprintf "from %s" whom [<EntryPoint>] let main argv = let message = from "F#" // Call the function let app = CommandApp() app.Configure(fun config -> config.AddBranch("add", fun (add: IConfigurator<AddSettings>) -> add.AddCommand<AddPackageCommand>("package") |> ignore add.AddCommand<AddReferenceCommand>("reference") |> ignore ) ) app.Run(argv)
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda