提交 012ec445 编写于 作者: M Marek Habersack

[asp.net] MinimizableAttributeTypeConverter only converts from strings.

It returns a boolean 'false' when the passed string matches (case-insensitively) 'false' or
is empty, returns 'true' otherwise.
All the other types (and a null value) cause it to throw the NotSupportedException.
上级 70902a33
......@@ -59,17 +59,22 @@ namespace System.Web.UI
public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
{
// culture?
string typeName;
if (value != null) {
Type t = value.GetType ();
if (t == typeof (string))
return ((string)value) != String.Empty;
if (t == typeof (string)) {
string s = value as string;
if (String.IsNullOrEmpty (s) || String.Compare (s, "false", StringComparison.OrdinalIgnoreCase) == 0)
return false;
else
return true;
}
typeName = t.FullName;
} else
typeName = "null";
if (t == typeof (bool))
return value;
}
return base.ConvertFrom (context, culture, value);
throw new NotSupportedException (String.Format ("MinimizableAttributeTypeConverter cannot convert from {0}", typeName));
}
}
......
......@@ -37,6 +37,8 @@ using System.Web.UI.HtmlControls;
using System.Reflection;
using NUnit.Framework;
using MonoTests.Common;
#if NET_2_0
namespace MonoTests.System.Web.UI {
......@@ -91,9 +93,27 @@ namespace MonoTests.System.Web.UI {
public void ConvertFrom ()
{
TypeConverter tc = GetTypeConverter ();
Assert.AreEqual ("hi", tc.ConvertTo ("hi", typeof (string)), "A1");
Assert.AreEqual ("", tc.ConvertTo ("", typeof (string)), "A2");
var culture = global::System.Globalization.CultureInfo.InvariantCulture;
Assert.AreEqual (true, tc.ConvertFrom (null, culture, "hi"), "A1");
Assert.AreEqual (false, tc.ConvertFrom (null, culture, String.Empty), "A2");
Assert.AreEqual (false, tc.ConvertFrom (null, culture, "false"), "A3");
Assert.AreEqual (false, tc.ConvertFrom (null, culture, "False"), "A4");
Assert.AreEqual (false, tc.ConvertFrom (null, culture, "FALSE"), "A5");
Assert.AreEqual (true, tc.ConvertFrom (null, culture, "true"), "A6");
Assert.AreEqual (true, tc.ConvertFrom (null, culture, "True"), "A");
AssertExtensions.Throws<NotSupportedException> (() => {
tc.ConvertFrom (null, culture, true);
}, "A8");
AssertExtensions.Throws<NotSupportedException> (() => {
tc.ConvertFrom (null, culture, false);
}, "A9");
AssertExtensions.Throws<NotSupportedException> (() => {
tc.ConvertFrom (null, culture, 1234);
}, "A10");
AssertExtensions.Throws<NotSupportedException> (() => {
tc.ConvertFrom (null, culture, null);
}, "A11");
}
[Test]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册