mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-17 11:21:39 -10:00
* Yups! Another milestone reached. System.Web assembly build successfully. svn path=/trunk/mcs/; revision=3156
66 lines
1.5 KiB
C#
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);
|
|
}
|
|
return ConvertTo(context, culture, value, destinationType);
|
|
}
|
|
}
|
|
}
|