Files
mono/mcs/class/System.Web/System.Web.UI.WebControls/UnitConverter.cs
T
Gaurav Vaish 27ddbc930c 2002-01-30 Gaurav Vaish <[email protected]>
* UnitConverter.cs -- Completed

* ValidatedControlConverter.cs -- Looks complete. Doubtful though!! :((

* ValidationSummary.cs -- Initial Implementation

* ChangeLog  -- Details of what happened today

* TODO  -- Marks updated

svn path=/trunk/mcs/; revision=2198
2002-01-30 11:50:39 +00:00

66 lines
1.5 KiB
C#

/**
* Namespace: System.Web.UI.WebControls
* Class: UnitConverter
*
* Author: Gaurav Vaish
* Maintainer: [email protected]
* Contact: <[email protected]>, <[email protected]>
* Implementation: yes
* Status: 100%
*
* (C) Gaurav Vaish (2002)
*/
using System;
using System.Globalization;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
namespace System.Web.UI.WebControls
{
public class UnitConverter : TypeConverter
{
public UnitConverter(): base()
{
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if(sourceType == typeof(string))
return true;
return CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if(value == null)
return null;
if(value is string)
{
string val = ((string)value).Trim();
if(val.Length == 0)
{
return Unit.Empty;
}
return (culture == null ? Unit.Parse(val) : Unit.Parse(val, culture));
}
return ConvertFrom(context, culture, value);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if(destinationType == typeof(string))
{
Unit val = (Unit)value;
if(val == Unit.Empty)
{
return String.Empty;
}
return val.ToString(culture);
}
ConvertTo(context, culture, value, destinationType);
}
}
}