I have recently become aware that our code has several implementations of a version parser (that is code to create a Version object from a version string). Thinking this was one of those times when people could not be bothered to read the docs I figured I would jump into MSDN, find the “standard” method to do this and replace the various methods with calls to that one. Much to my surprise the Version class does not have a Parse method, nor is there one on Convert or anywhere else that I searched.
Am I just missing it, or is there no method in the .Net API for converting a version string to a Version object. Please note I have the code to do it. In fact I have two different approaches that are being used in several different methods. What I am looking for is one in the standard library.
This issue is that the Version string we get from our hardware is not a “standard” version string. It is of the form major.minor.patch (build), rather than major.minor.build.patch.
Could you write an Extension method for a
Version.Parse
? That way it would be in one place.In C#…
In VB…
What about the constructor that takes a string?
I guess the “standard method” you are looking for is the Version constructor with a single string parameter?