-Maded explicit JValue conversions more flexible converting values

-Added implicit conversions for Uri, TimeSpan, Guid
-Fixed JValue constructors for Uri, TimeSpan, Guid assigning incorrect JTokenType
This commit is contained in:
James Newton-King
2012-11-20 00:44:04 +13:00
parent a6b94d2a13
commit 9160416fc3
6 changed files with 232 additions and 76 deletions
@@ -333,6 +333,44 @@ If attributes are not mentioned, default values are used in each case.
}, "New");
}
[Test]
public void JTokenToObject()
{
JValue s = new JValue("String!");
int interations = 1000000;
TimeOperation(() =>
{
for (int i = 0; i < interations; i++)
{
s.ToObject(typeof (string));
}
return "";
}, "New");
TimeOperation(() =>
{
for (int i = 0; i < interations; i++)
{
s.ToObject(typeof(string), new JsonSerializer());
}
return "";
}, "Old");
TimeOperation(() =>
{
for (int i = 0; i < interations; i++)
{
s.Value<string>();
}
return "";
}, "Value");
}
private void SerializeSize(object value)
{
// this is extremely slow with 5000 interations