[corlib] Avoid unnecessary ephemeron array resizes
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Converters / OutlineViewTextConverter.cs
1 //----------------------------------------------------------------
2 // <copyright company="Microsoft Corporation">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //----------------------------------------------------------------
6
7 namespace System.Activities.Presentation.Converters
8 {
9     using System.Activities.Presentation.Model;
10     using System.Globalization;
11     using System.Runtime;
12     using System.Windows;
13     using System.Windows.Data;
14     using Microsoft.Activities.Presentation;
15
16     internal class OutlineViewTextConverter : IMultiValueConverter
17     {
18         public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
19         {
20             string displayName = string.Empty;
21             if (values[0] != DependencyProperty.UnsetValue)
22             {
23                 displayName = values[0] as string;
24             }
25
26             if (string.IsNullOrEmpty(displayName) && values[1] != DependencyProperty.UnsetValue)
27             {
28                 ModelItem modelItem = values[1] as ModelItem;
29                 if (modelItem != null)
30                 {
31                     ModelProperty nameProperty = modelItem.Properties["Name"];
32                     if (nameProperty != null && nameProperty.Value != null)
33                     {
34                         displayName = nameProperty.Value.GetCurrentValue() as string;
35                     }
36
37                     if (string.IsNullOrEmpty(displayName))
38                     {
39                         Fx.Assert(modelItem.ItemType != null && modelItem.ItemType.Name != null, "ModelItem should always have a name");
40                         displayName = TypeNameHelper.GetDisplayName(modelItem.ItemType, false);
41                     }
42                 }
43             }
44
45             return displayName;
46         }
47
48         public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
49         {
50             throw FxTrace.Exception.AsError(new InvalidOperationException());
51         }
52     }
53 }