public DefaultValueAttribute(Type type, string value)
{
// The try/catch here is because attributes should never throw exceptions. We would fail to
// load an otherwise normal class.
try
{
if (type.IsSubclassOf(typeof(Enum)))
{
this.value = Enum.Parse(type, value, true);
}
else if (type == typeof(TimeSpan))
{
this.value = TimeSpan.Parse(value);
}
else
{
this.value = Convert.ChangeType(value, type, CultureInfo.InvariantCulture);
}
}
catch
{
//Debug.WriteLine("Default value attribute of type " + type.ToString() + " threw converting from the string '" + value + "'.");
}
}