Skip to content

Parser.ParseArguments(factory, args) requires parameterless constructor#310

@Virtlink

Description

@Virtlink

The Parser.ParseArguments() overloads with a factory function has this signature:

public ParserResult<T> ParseArguments<T>(Func<T> factory, IEnumerable<string> args) where T : new() 

If I provide my own factory function, why does T need to have a public parameterless constructor (new())?

var result = parser.ParseArguments<Options>(() => new Options(true), args); 

And on the other hand, why doesn't the non-factory overload of ParseArgumentsnot require a public parameterless constructor? This will cause a runtime-exception when T doesn't have a public parameterless constructor.

var result = parser.ParseArguments<Options>(args); 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions