[corlib] Avoid unnecessary ephemeron array resizes
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / Editors / NewItemFactoryTypeModelToDisplayNameConverter.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.Editors 
5 {
6     using System;
7     using System.Windows.Data;
8     using System.Globalization;
9
10     using System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.PropertyInspector;
11     using System.Activities.Presentation;
12
13     // <summary>
14     // Converts an instance of NewItemFactoryTypeModel to its appropriate display name.
15     // One way binding to NewItemFactoryTypeModel's DisplayName property also works, but
16     // for the sake of having a single place that converts NewItemFactoryTypeModel to
17     // strings, we expose this internal converter.
18     // </summary>
19     internal class NewItemFactoryTypeModelToDisplayNameConverter : IValueConverter 
20     {
21
22         private static NewItemFactoryTypeModelToDisplayNameConverter _instance;
23
24         // <summary>
25         // Static instance accessor for all non-XAML related conversion needs
26         // </summary>
27         public static NewItemFactoryTypeModelToDisplayNameConverter Instance 
28         {
29             get {
30                 if (_instance == null)
31                 {
32                     _instance = new NewItemFactoryTypeModelToDisplayNameConverter();
33                 }
34
35                 return _instance;
36             }
37         }
38
39         // Converts an instance of NewItemFactoryTypeModel to its appropriate display name
40         public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
41         {
42
43             if (typeof(string).IsAssignableFrom(targetType)) 
44             {
45
46                 NewItemFactoryTypeModel model = value as NewItemFactoryTypeModel;
47                 if (model != null) 
48                 {
49                     return model.DisplayName ?? string.Empty;
50                 }
51             }
52
53             return string.Empty;
54         }
55
56         // This class is only a one-way converter
57         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
58         {
59             throw FxTrace.Exception.AsError(new InvalidOperationException());
60         }
61     }
62 }