forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextTrimConverter.cs
More file actions
72 lines (63 loc) · 2.5 KB
/
Copy pathTextTrimConverter.cs
File metadata and controls
72 lines (63 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//-----------------------------------------------------------------------
// <copyright file="TextTrimConverter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Microsoft.Management.UI.Internal
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
/// <summary>
/// Removes whitespace at beginning and end of a string.
/// </summary>
[SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
public class TextTrimConverter : IValueConverter
{
/// <summary>
/// Creates a new TextTrimConverter. By default, both conversion directions are trimmed.
/// </summary>
public TextTrimConverter()
{
}
#region IValueConverter Members
/// <summary>
/// Trims excess whitespace from the given string.
/// </summary>
/// <param name="value">original string</param>
/// <param name="targetType">The parameter is not used.</param>
/// <param name="parameter">The parameter is not used.</param>
/// <param name="culture">The parameter is not used.</param>
/// <returns>The trimmed string.</returns>
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return TrimValue(value);
}
private static object TrimValue(object value)
{
string strValue = value as string;
if (strValue == null)
{
return value;
}
return strValue.Trim();
}
/// <summary>
/// Trims extra whitespace from the given string during backward conversion.
/// </summary>
/// <param name="value">original string</param>
/// <param name="targetType">The parameter is not used.</param>
/// <param name="parameter">The parameter is not used.</param>
/// <param name="culture">The parameter is not used.</param>
/// <returns>The trimmed string.</returns>
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return TrimValue(value);
}
#endregion
}
}