[reflection] Coop handles icalls in System.Reflection and System.RuntimeTypeHandle...
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / NonTextualExpressionMorphHelper.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4
5 namespace System.Activities.Presentation
6 {
7     using System;
8     using System.Activities.Presentation.Expressions;
9     using System.Activities.Presentation.Model;
10     using System.Activities.Presentation.Services;
11     using System.Activities.Presentation.View;
12     using System.Collections.Generic;
13     using System.Linq;
14     using System.Runtime;
15     using System.Text;
16     using Microsoft.VisualBasic.Activities;
17
18     //This serves as expression morph helper for following non-textual expressions:
19     //1) Literal<T>
20     //2) VariableValue<T>/VariableReference<T>
21     //The helper will morph these expressions to what specified at root object by ExpressionActivityEditor attached property
22     class NonTextualExpressionMorphHelper : ExpressionMorphHelper
23     {
24         public override bool TryMorphExpression(ActivityWithResult expression, bool isLocationExpression, Type newType, 
25             EditingContext context, out ActivityWithResult newExpression)
26         {
27             Fx.Assert(expression != null, "Original expression shouldn't be null in morph helper");
28             Fx.Assert(context != null, "EditingContext shouldn't be null in morph helper");
29             newExpression = null;
30             if (expression.ResultType == newType && 
31                 (ExpressionHelper.IsGenericLocationExpressionType(expression) == isLocationExpression))
32             {
33                 newExpression = expression;
34                 return true;
35             }
36
37             if (context != null)
38             {
39                 string expressionEditor = ExpressionHelper.GetRootEditorSetting(context.Services.GetService<ModelTreeManager>(), WorkflowDesigner.GetTargetFramework(context));
40                 ParserContext parserContext = new ParserContext();
41                 string expressionText = ExpressionHelper.GetExpressionString(expression, parserContext);
42                 if (!string.IsNullOrEmpty(expressionEditor))
43                 {
44                     return ExpressionTextBox.TryConvertFromString(expressionEditor, expressionText, isLocationExpression, newType, out newExpression);
45                 }
46             }
47
48             return false;
49         }
50     }
51 }