fa413e97a3170f421666dafc64edd42497dc5809
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / Automation / TextFormatConverter.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.Automation 
5 {
6     using System;
7     using System.Diagnostics.CodeAnalysis;
8     using System.Globalization;
9     using System.Windows.Data;
10     using System.Activities.Presentation;
11
12     // <summary>
13     // Simple converter that uses a format string to convert a value into a display string
14     // This class is referenced in XAML.
15     // </summary>
16     [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
17     internal class TextFormatConverter : IValueConverter 
18     {
19
20         private string _format;
21
22         // <summary>
23         // Gets or sets the format string to apply
24         // </summary>
25         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
26         public string Format 
27         {
28             get {
29                 return _format;
30             }
31             set {
32                 _format = value;
33             }
34         }
35
36         // IValueConverter Members
37
38         public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
39         {
40             value = value ?? "null";
41             return string.Format(culture ?? CultureInfo.CurrentCulture, _format ?? "{0}", value.ToString());
42         }
43
44         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
45         {
46             throw FxTrace.Exception.AsError(new InvalidOperationException());
47         }
48
49     }
50 }