Download CustomTypeConverter3.zip version 1.0.0.0, last updated 28/07/2013 (14.36 KB)

Download
  • md5: 12dfe9b74b052e3c18cd0c878b92b8f9
using System.ComponentModel;
using System.Globalization;

/*
  Custom Type Converter Sample 3
  http://cyotek.com/blog/using-alternate-descriptions-for-enumeration-members
*/

namespace CustomTypeConverter3
{
  [TypeConverter(typeof(LengthConverter))]
  internal class Length
  {
    #region Constructors

    public Length()
    { }

    public Length(float value, Unit unit)
      : this()
    {
      this.Value = value;
      this.Unit = unit;
    }

    #endregion

    #region Overridden Members

    public override string ToString()
    {
      string value;
      string unit;

      value = this.Value.ToString(CultureInfo.InvariantCulture);
      unit = this.Unit.GetDescription();

      return string.Concat(value, unit);
    }

    #endregion

    #region Properties

    [DefaultValue(typeof(Unit), "None")]
    public Unit Unit { get; set; }

    [DefaultValue(0F)]
    public float Value { get; set; }

    #endregion
  }
}

Donate

Donate