Nibble

Umbraco V7/ Belle Compatibility Helper

Now that Umbraco 7 alpha is out http://umbraco.com/follow-us/blog-archive/2013/9/27/umbraco-7-alpha-is-here.aspx you can start testing your packages.

Here is a little helper that you can use in your Umbraco projects to identify if you are running v7 or older/newer (useful if you have a package you want to upgrade and want to perform a different action depending on the Umbraco version)

    public class CompatibilityHelper
    {
      
        public static bool IsVersion7OrNewer
        {
            get
            {
                var retval = true;
                try
                {
                    typeof(umbraco.uicontrols.CodeArea).InvokeMember("Menu",
                             BindingFlags.GetField, null, new umbraco.uicontrols.CodeArea(), null);
                }
                catch (MissingFieldException e)
                {
                    retval = false;
                }
 
                return retval;
            }
        }
       
    }

It basically checks if the umbraco.uicontrols.CodeArea has the Menu field (which was added in v7 so if that fails it’s an older version)

6 Comments so far

  1. Tim Geyssens on September 28th, 2013

    Would be good to add some caching to it…

  2. Morten Christensen on September 28th, 2013

    You could also use the UmbracoVersion class which returns a proper Version object:
    var version = Umbraco.Core.Configuration.UmbracoVersion.Current;
    ;-)
    - Morten

  3. Tim Geyssens on September 28th, 2013

    @Morten, yeah but when did that one get added?

  4. Morten Christensen on September 28th, 2013

    In one of the early version 6 releases. Don’t remember exactly which one. So obviously not available in v.4.x.

  5. Richard Soeteman on November 1st, 2013

    Hi Tim,

    Try Catch is quite expensive to use. I’m using a check on the version also

    public static bool SupportsBelle
    {
    get
    {
    return GlobalSettings.CurrentVersion.StartsWith(”7″);
    }
    }

    For the rest keep the good blogposts coming!

  6. Tim Geyssens on November 4th, 2013

    @Richard I did add some caching :)

Leave a Reply