|
using System;
using System.ComponentModel;
using System.Globalization;
using Codebasement.DomainDrivenDesign.Basement.Utilities;
namespace Codebasement.DomainDrivenDesign.Model.Converters
{
/// <summary>
/// The passwordstring converter can be used to mask the display of a password setting.
/// </summary>
public class PasswordStringConverter : StringConverter
{
/// <summary>
/// This method is implemented to tell that the converter cannot convert from the given format.
/// </summary>
/// <param name="context"></param>
/// <param name="sourceType"></param>
/// <returns>false</returns>
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return false;
}
/// <summary>
/// This method returns a masked string that will be displayed in the design pane.
/// </summary>
/// <param name="context"></param>
/// <param name="culture"></param>
/// <param name="value"></param>
/// <param name="destinationType"></param>
/// <returns>A string containing password-dots.</returns>
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value,
Type destinationType)
{
return String.Empty.PadLeft(((string) value).Length, RegexExpressions.PasswordChar);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.