[amd64/tramp] hide interpreter specific trampoline behind ifdef
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Converters / ModelPropertyEntryToOwnerActivityConverter.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4
5 namespace System.Activities.Presentation.Converters
6 {
7     using System.Activities.Presentation.Internal.PropertyEditing.Model;
8     using System.Activities.Presentation.Model;
9     using System.Globalization;
10     using System.Runtime;
11     using System.ServiceModel.Activities;
12     using System.Windows.Data;
13
14     // This type converter converts from ModelPropertyEntry to ModelItem that owns the property
15     public class ModelPropertyEntryToOwnerActivityConverter : IValueConverter
16     {
17         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
18         {
19             //converter can be parametrized - by default, always return parent model item of type Activity or WorkflowService, 
20             //but if false is passed in - simply return first parent
21             bool returnParentWorkflowElement = true;
22             if (null != parameter && parameter is bool)
23             {
24                 returnParentWorkflowElement = (bool)parameter;
25             }
26
27             return ModelPropertyEntryToOwnerActivityConverter.Convert(value as ModelPropertyEntry, returnParentWorkflowElement);
28         }
29
30         internal static ModelItem Convert(ModelPropertyEntry modelPropertyEntry, bool returnParentActivity)
31         {
32             ModelItem convertedValue = null;
33             if (modelPropertyEntry != null)
34             {
35                 ModelProperty property = modelPropertyEntry.FirstModelProperty;
36                 if (property != null)
37                 {
38                     convertedValue = property.Parent;
39                     if (returnParentActivity)
40                     {
41                         while (convertedValue != null)
42                         {
43                             Type itemType = convertedValue.ItemType;
44                             if (typeof(Activity).IsAssignableFrom(itemType) || typeof(WorkflowService).IsAssignableFrom(itemType))
45                             {
46                                 break;
47                             }
48
49                             convertedValue = convertedValue.Parent;
50                         }
51                     }
52                 }
53             }
54
55             return convertedValue;
56         }
57
58         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
59         {
60             Fx.Assert("this value converter only works on the forward direction");
61             return null;
62         }
63     }
64 }