[jayrock] 3 new revisions pushed by azizatif on 2011-05-01 23:49 GMT

2 views
Skip to first unread message

jay...@googlecode.com

unread,
May 1, 2011, 7:50:04 PM5/1/11
to jayrock...@googlegroups.com
3 new revisions:

Revision: 0b36385f1b39
Author: azizatif
Date: Sat Apr 30 14:43:02 2011
Log: Added conversion operator for BigInteger to JsonNumber
http://code.google.com/p/jayrock/source/detail?r=0b36385f1b39

Revision: 69c8c94dc7f3
Author: azizatif
Date: Sun May 1 16:44:24 2011
Log: Added a JsonObject ctor to initialize from a JsonMember sequence
http://code.google.com/p/jayrock/source/detail?r=69c8c94dc7f3

Revision: ded3ff6285c6
Author: azizatif
Date: Sun May 1 16:45:19 2011
Log: Refactored JsonMemberNamingConventionAttribute internals
http://code.google.com/p/jayrock/source/detail?r=ded3ff6285c6

==============================================================================
Revision: 0b36385f1b39
Author: azizatif
Date: Sat Apr 30 14:43:02 2011
Log: Added conversion operator for BigInteger to JsonNumber
http://code.google.com/p/jayrock/source/detail?r=0b36385f1b39

Modified:
/src/Jayrock.Json/Json/JsonNumber.cs

=======================================
--- /src/Jayrock.Json/Json/JsonNumber.cs Fri Apr 15 16:09:54 2011
+++ /src/Jayrock.Json/Json/JsonNumber.cs Sat Apr 30 14:43:02 2011
@@ -152,6 +152,11 @@
{
return System.Numerics.BigInteger.Parse(Value,
NumberStyles.Integer, provider);
}
+
+ public static explicit operator
System.Numerics.BigInteger(JsonNumber number)
+ {
+ return number.ToBigInteger();
+ }

#endif // !NET_1_0 && !NET_1_1 && !NET_2_0


==============================================================================
Revision: 69c8c94dc7f3
Author: azizatif
Date: Sun May 1 16:44:24 2011
Log: Added a JsonObject ctor to initialize from a JsonMember sequence
http://code.google.com/p/jayrock/source/detail?r=69c8c94dc7f3

Modified:
/src/Jayrock.Json/Json/JsonObject.cs
/tests/Jayrock/Json/TestJsonObject.cs

=======================================
--- /src/Jayrock.Json/Json/JsonObject.cs Fri Apr 15 16:09:54 2011
+++ /src/Jayrock.Json/Json/JsonObject.cs Sun May 1 16:44:24 2011
@@ -140,18 +140,29 @@
return GetEnumerator();
}

-#if !NET_1_0 && !NET_1_1
+ #if !NET_1_0 && !NET_1_1
+
+ public JsonObject(IEnumerable<JsonMember> members)
+ {
+ if (members == null)
+ return;
+
+ foreach (JsonMember member in members)
+ Accumulate(member.Name, member.Value);
+ }
+
IEnumerator<JsonMember> IEnumerable<JsonMember>.GetEnumerator()
{
return GetEnumerator();
}
-#endif
+
+ #endif

[Serializable]
public sealed class JsonMemberEnumerator : IEnumerator, IDisposable
-#if !NET_1_0 && !NET_1_1
+ #if !NET_1_0 && !NET_1_1
, IEnumerator<JsonMember>
-#endif
+ #endif
{
private JsonObject _obj;
private IEnumerator _enumerator;
=======================================
--- /tests/Jayrock/Json/TestJsonObject.cs Fri Apr 15 16:09:54 2011
+++ /tests/Jayrock/Json/TestJsonObject.cs Sun May 1 16:44:24 2011
@@ -40,6 +40,7 @@
#if !NET_1_0 && !NET_1_1 && !NET_2_0

using System.Dynamic;
+ using System.Linq;
using System.Linq.Expressions;
using Microsoft.CSharp.RuntimeBinder;

@@ -639,6 +640,30 @@
Assert.AreEqual(obj.GetEnumerator().GetType(), ((IEnumerable)
obj).GetEnumerator().GetType());
}

+ #if !NET_2_0
+
+ [ Test ]
+ public void InitWithJsonMemberSequence()
+ {
+ JsonObject obj = new JsonObject(
+ from i in Enumerable.Range(0, 10)
+ let ch = (char)('a' + i)
+ select new JsonMember(ch.ToString(), i));
+
+ Assert.AreEqual(10, obj.Count);
+ Assert.AreEqual(0, obj["a"]);
+ Assert.AreEqual(1, obj["b"]);
+ Assert.AreEqual(2, obj["c"]);
+ Assert.AreEqual(3, obj["d"]);
+ Assert.AreEqual(4, obj["e"]);
+ Assert.AreEqual(5, obj["f"]);
+ Assert.AreEqual(6, obj["g"]);
+ Assert.AreEqual(7, obj["h"]);
+ Assert.AreEqual(8, obj["i"]);
+ Assert.AreEqual(9, obj["j"]);
+ }
+
+ #endif // !NET_2_0
#endif // !NET_1_0 && !NET_1_1
}
}

==============================================================================
Revision: ded3ff6285c6
Author: azizatif
Date: Sun May 1 16:45:19 2011
Log: Refactored JsonMemberNamingConventionAttribute internals
http://code.google.com/p/jayrock/source/detail?r=ded3ff6285c6

Modified:
/src/Jayrock.Json/Json/Conversion/JsonMemberNamingConventionAttribute.cs
/tests/Jayrock/Json/Conversion/TestJsonMemberNamingConventionAttribute.cs

=======================================
---
/src/Jayrock.Json/Json/Conversion/JsonMemberNamingConventionAttribute.cs
Tue Apr 26 18:35:26 2011
+++
/src/Jayrock.Json/Json/Conversion/JsonMemberNamingConventionAttribute.cs
Sun May 1 16:45:19 2011
@@ -28,6 +28,7 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
+ using System.Text;

#endregion

@@ -84,41 +85,57 @@
if (property == null)
throw new ArgumentNullException("property");

- if (Convention == NamingConvention.None && Underscores ==
UnderscoreConvention.None)
+ NamingConvention naming = Convention;
+ UnderscoreConvention underscoring = Underscores;
+ if (naming == NamingConvention.None && underscoring ==
UnderscoreConvention.None)
return;
-
- string name = property.Name;
-
- switch (Underscores)
+ SetName(property, FormatName(FormatName(property.Name,
underscoring), naming));
+ }
+
+ private static string FormatName(string name, UnderscoreConvention
underscoring)
+ {
+ switch (underscoring)
{
case UnderscoreConvention.Prefix:
- if (name.Length > 0 && name[0] != '_')
- name = '_' + name;
- break;
+ return name.Length > 0 && name[0] != '_'
+ ? '_' + name : name;
case UnderscoreConvention.Separate:
+ StringBuilder sb = null;
for (int i = 1; i < name.Length; ++i)
{
- if (char.IsUpper(name[i])) {
- name = name.Substring(0, i) + '_' +
name.Substring(i);
- ++i;
- }
- }
- break;
- }
-
- switch (Convention)
+ char ch = name[i];
+ if (char.IsUpper(ch))
+ {
+ if (sb == null)
+ {
+ sb = new StringBuilder();
+ sb.Append(name, 0, i);
+ }
+ sb.Append('_');
+ }
+ if (sb != null) sb.Append(ch);
+ }
+ return sb != null ? sb.ToString() : name;
+ default:
+ return name;
+ }
+ }
+
+ private static string FormatName(string name, NamingConvention
naming)
+ {
+ switch (naming)
{
case NamingConvention.Pascal:
- name = char.ToUpper(name[0],
CultureInfo.InvariantCulture) + name.Substring(1); break;
+ return char.ToUpper(name[0],
CultureInfo.InvariantCulture) + name.Substring(1);
case NamingConvention.Camel:
- name = char.ToLower(name[0],
CultureInfo.InvariantCulture) + name.Substring(1); break;
+ return char.ToLower(name[0],
CultureInfo.InvariantCulture) + name.Substring(1);
case NamingConvention.Upper:
- name = name.ToUpper(CultureInfo.InvariantCulture);
break;
+ return name.ToUpper(CultureInfo.InvariantCulture);
case NamingConvention.Lower:
- name = name.ToLower(CultureInfo.InvariantCulture);
break;
- }
-
- SetName(property, name);
+ return name.ToLower(CultureInfo.InvariantCulture);
+ default:
+ return name;
+ }
}

private static void SetName(PropertyDescriptor property, string
name)
=======================================
---
/tests/Jayrock/Json/Conversion/TestJsonMemberNamingConventionAttribute.cs
Sun Apr 17 16:27:53 2011
+++
/tests/Jayrock/Json/Conversion/TestJsonMemberNamingConventionAttribute.cs
Sun May 1 16:45:19 2011
@@ -61,7 +61,8 @@
}

[Test]
- public void SetConvention() {
+ public void SetConvention()
+ {
JsonMemberNamingConventionAttribute attribute = new
JsonMemberNamingConventionAttribute();
Assert.AreEqual(NamingConvention.None, attribute.Convention);
attribute.Convention = NamingConvention.Pascal;
@@ -69,7 +70,8 @@
}

[Test]
- public void SetUnderscores() {
+ public void SetUnderscores()
+ {
JsonMemberNamingConventionAttribute attribute = new
JsonMemberNamingConventionAttribute();
Assert.AreEqual(UnderscoreConvention.None,
attribute.Underscores);
attribute.Underscores = UnderscoreConvention.Separate;
@@ -144,7 +146,8 @@
}

[Test]
- public void UnderscorePrefixApplication() {
+ public void UnderscorePrefixApplication()
+ {
TestNamingCase("FooBarBaz", NamingConvention.Camel,
UnderscoreConvention.Prefix, "_FooBarBaz");
TestNamingCase("FooBarBaz", NamingConvention.Pascal,
UnderscoreConvention.Prefix, "_FooBarBaz");
TestNamingCase("FooBarBaz", NamingConvention.Upper,
UnderscoreConvention.Prefix, "_FOOBARBAZ");
@@ -152,11 +155,13 @@
}

[Test]
- public void UnderscoreSeparatorApplication() {
+ public void UnderscoreSeparatorApplication()
+ {
TestNamingCase("FooBarBaz", NamingConvention.Camel,
UnderscoreConvention.Separate, "foo_Bar_Baz");
TestNamingCase("FooBarBaz", NamingConvention.Pascal,
UnderscoreConvention.Separate, "Foo_Bar_Baz");
TestNamingCase("FooBarBaz", NamingConvention.Upper,
UnderscoreConvention.Separate, "FOO_BAR_BAZ");
TestNamingCase("FooBarBaz", NamingConvention.Lower,
UnderscoreConvention.Separate, "foo_bar_baz");
+ TestNamingCase("foobarbaz", NamingConvention.None,
UnderscoreConvention.Separate, "foobarbaz");
}

private static void TestNamingCase(string baseName,
NamingConvention testCase, UnderscoreConvention testUnder, string expected)

Reply all
Reply to author
Forward
0 new messages