The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,927 other followers

C# code fragment of the week

Posted by jpluimers on 2012/07/24

Please don’t do your code like this:

        internal bool blnMDACResult = true;

        internal bool CheckMDACisOK(string eenMDAC, string strAdoDllPath)
        {
            FileVersionInfo AdoVersionInfo;

            try
            {
                AdoVersionInfo = FileVersionInfo.GetVersionInfo(strAdoDllPath);
                AdoDllVersion = new Version(AdoVersionInfo.ProductMajorPart, AdoVersionInfo.ProductMinorPart, AdoVersionInfo.ProductBuildPart, AdoVersionInfo.ProductPrivatePart);

                switch (eenMDAC)
                {
                    case "2.6":
                    case "2,6":
                        // MDAC 2.6 - 2.60.6526.0
                        Version MinimumVersion = new Version(2, 60, 6526, 0);
                        blnMDACResult = AdoDllVersion.CompareTo(MinimumVersion) >= 0;
                        break;

                    case "2.7":
                    case "2,7":
                        // MDAC 2.7 - 2.70.7713.0
                        Version MinimumVersion = new Version(2, 70, 7713, 0);
                        blnMDACResult = AdoDllVersion.CompareTo(MinimumVersion) >= 0;
                        break;

                    case "2.8":
                    case "2,8":
                        // MDAC 2.8 - 2.80.1022.0
                        Version MinimumVersion = new Version(2, 80, 1022, 0);
                        blnMDACResult = AdoDllVersion.CompareTo(MinimumVersion) >= 0;
                        break;

                    default:
                        // 2.9 and up
                        string numberDecimalSeparator = Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator;
                        double dMinVersion = ConvertAppl.ToDouble(eenMDAC.Replace(".", numberDecimalSeparator));
                        double dVersion = ConvertAppl.ToDouble(AdoDllVersion.Major + ".".Replace(".", numberDecimalSeparator) + AdoDllVersion.Minor);
                        if (dVersion > dMinVersion)
                            blnMDACResult = true;
                        else
                            blnMDACResult = false;
                        break;
                }
            }
            catch
            {
                // Something went wrong, let's assume the version is ok. (trial on error)
                blnMDACResult = true;
                return blnMDACResult;
            }

            return blnMDACResult;

        }

–jeroen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: