Skip to content

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

@ericnewton76

Description

@ericnewton76

Issue by Virtlink
Sunday Apr 24, 2016 at 11:12 GMT
Originally opened as gsscoder/commandline#310


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 ParseArguments not 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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions