tags:

views:

40

answers:

4

I have recently become aware that our code has serveral 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 serveral different methods. What I am looking for is one in the standard library.

Pat O

A: 

Could you write an Extension method for a Version.Parse? That way it would be in one place.

In C#...

Version Parse(this Version ver, string Value) {
    // your conversion here.
}

In VB...

Imports System.Runtime.CompilerServices

Module VersionExtensions

    <Extension()> _
    Public Function Parse(ByVal aVersion As Version, ByVal aValue As String) As Version
        ' Conversion Here
    End Function

End Module
Daniel A. White
+3  A: 

What about the constructor that takes a string?

bdukes
A: 

I guess the "standard method" you are looking for is the Version constructor with a single string parameter?

devio
A: 

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.

Pat O