Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Activities.Core.Presentation / System / ServiceModel / Activities / Presentation / ActivityXRefConverter.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4
5 namespace System.ServiceModel.Activities.Presentation
6 {
7     using System;
8     using System.Globalization;
9     using System.Windows.Data;
10     using System.Activities.Presentation.Model;
11     using System.Activities;
12     using System.Activities.Core.Presentation;
13
14     sealed class ActivityXRefConverter : IValueConverter
15     {
16         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
17         {
18             if (!(targetType == typeof(string) || targetType == typeof(object)))
19             {
20                 throw FxTrace.Exception.AsError(new NotSupportedException());
21             }
22             if (null == value)
23             {
24                 throw FxTrace.Exception.AsError(new ArgumentNullException("value"));
25             }
26             ModelItem activity = value as ModelItem;
27             string displayName = value as string;
28             
29             string formatString = (parameter as string) ?? "{0}";
30
31             if (null != activity && typeof(Activity).IsAssignableFrom(activity.ItemType))
32             {
33                 displayName = ((string)activity.Properties["DisplayName"].ComputedValue);
34             }
35
36             if (null == displayName)
37             {
38                 displayName = "<null>";
39             }
40             else if (displayName.Length == 0)
41             {
42                 displayName = "...";
43             }
44
45             return string.Format(CultureInfo.CurrentUICulture, formatString, displayName);
46         }
47
48         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
49         {
50             throw FxTrace.Exception.AsError(new NotSupportedException());
51         }
52     }
53 }