ff2a8ea12604840513bba5ec9652ba925b6052a4
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / Microsoft.Tools.Common / Microsoft / Activities / Presentation / ExpressionSettingHelper.cs
1 //----------------------------------------------------------------
2 // <copyright company="Microsoft Corporation">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //----------------------------------------------------------------
6
7 namespace Microsoft.Activities.Presentation
8 {
9     using System.Activities.Expressions;
10 using System.Activities.Presentation.Expressions;
11 using System.Activities.Presentation.Model;
12 using System.Diagnostics;
13 using System.Diagnostics.CodeAnalysis;
14 using System.Runtime.Versioning;
15 using Microsoft.VisualBasic.Activities;
16
17     internal static class ExpressionSettingHelper
18     {
19         internal static readonly string VBExpressionLanguageName = (new VisualBasicValue<string>() as ITextExpression).Language;
20
21         [SuppressMessage("Reliability", "Reliability101", Justification = "We can't use Fx.Assert here since this is not a framework assembly.")]
22         internal static string GetRootEditorSetting(ModelTreeManager modelTreeManager, FrameworkName targetFramework)
23         {
24             Debug.Assert(modelTreeManager != null, "modelTreeManager is null.");
25             Debug.Assert(targetFramework != null, "targetFramework is null.");
26
27             string globalEditorSetting = null;
28             if (Is45OrHigher(targetFramework))
29             {
30                 if (modelTreeManager != null)
31                 {
32                     ModelItem rootItem = modelTreeManager.Root;
33                     if (rootItem != null)
34                     {
35                         object root = rootItem.GetCurrentValue();
36                         globalEditorSetting = ExpressionActivityEditor.GetExpressionActivityEditor(root);
37                         if (string.IsNullOrEmpty(globalEditorSetting))
38                         {
39                             globalEditorSetting = VBExpressionLanguageName;
40                         }
41                     }
42                 }
43             }
44             else
45             {
46                 // When the target framework is less than 4.5, the root setting is ignored and always return VB
47                 globalEditorSetting = VBExpressionLanguageName;
48             }
49
50             return globalEditorSetting;
51         }
52
53         private static bool Is45OrHigher(FrameworkName frameworkName)
54         {
55             return frameworkName.Version.Major > 4 || (frameworkName.Version.Major == 4 && frameworkName.Version.Minor >= 5);
56         }
57     }
58 }