WalkerCodeRanger/semver

Add a constructor taking a string

Closed this issue · 1 comments

I'm suggesting to add a constructor of SemVersion that takes a string, i.e.

var version = new SemVersion("1.2.0-beta");

My particular use case is that I want to use SemVersion with System.CommandLine.DragonFruit, which will work automatically if there is a constructor taking a string. That is admittedly kind of an obscure use case, but such a constructor would also be consistent with the .NET Framework. For example, System.Version has such a constructor.

I'd be happy to create a PR for this if it's something you want.

I'm not inclined to add a constructor taking a string. I think the static Parse method style we follow is more widely followed in the .NET standard library etc. Not having the constructor is consistent with the plan to mark implicit conversion from string as obsolete in the next version.

I think the use of TryParse should be encouraged. Also, the plan is to add parameters to the parse method which controls what version number formats are accepted. So, while there will be an overload of parse that takes just a string, I don't think it makes sense to think of a semantic version as being constructible from a string without parsing.

I'd reconsider if there were explicit guidance from Microsoft on this or many more cases of classes constructible from string like this.