// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using System.Windows.Data; namespace Microsoft.Management.UI.Internal { /// /// Removes whitespace at beginning and end of a string. /// [SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")] public class TextTrimConverter : IValueConverter { /// /// Creates a new TextTrimConverter. By default, both conversion directions are trimmed. /// public TextTrimConverter() { } #region IValueConverter Members /// /// Trims excess whitespace from the given string. /// /// Original string. /// The parameter is not used. /// The parameter is not used. /// The parameter is not used. /// The trimmed string. 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(); } /// /// Trims extra whitespace from the given string during backward conversion. /// /// Original string. /// The parameter is not used. /// The parameter is not used. /// The parameter is not used. /// The trimmed string. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return TrimValue(value); } #endregion } }