[jayrock] 2 new revisions pushed by azizatif on 2011-04-29 22:40 GMT

2 views
Skip to first unread message

jay...@googlecode.com

unread,
Apr 29, 2011, 6:40:41 PM4/29/11
to jayrock...@googlegroups.com
2 new revisions:

Revision: 341932e10b78
Author: azizatif
Date: Fri Apr 29 15:29:25 2011
Log: Added support for exporting immutable types
http://code.google.com/p/jayrock/source/detail?r=341932e10b78

Revision: f39d1bcbde80
Author: azizatif
Date: Fri Apr 29 15:40:15 2011
Log: Added coverage for backing out of an immutable type definition
http://code.google.com/p/jayrock/source/detail?r=f39d1bcbde80

==============================================================================
Revision: 341932e10b78
Author: azizatif
Date: Fri Apr 29 15:29:25 2011
Log: Added support for exporting immutable types
http://code.google.com/p/jayrock/source/detail?r=341932e10b78

Modified:
/src/Jayrock.Json/Json/Conversion/CustomTypeDescriptor.cs
/tests/Jayrock/Json/Conversion/TestCustomTypeDescriptor.cs

=======================================
--- /src/Jayrock.Json/Json/Conversion/CustomTypeDescriptor.cs Mon Apr 18
16:56:38 2011
+++ /src/Jayrock.Json/Json/Conversion/CustomTypeDescriptor.cs Fri Apr 29
15:29:25 2011
@@ -107,7 +107,7 @@
}

PropertyDescriptorCollection logicalProperties = new
PropertyDescriptorCollection(null);
-
+ bool immutable = true;
int index = 0;

foreach (MemberInfo member in members)
@@ -115,6 +115,7 @@
FieldInfo field = member as FieldInfo;
string name = names != null && index < names.Length ?
names[index] : null;
TypeMemberDescriptor descriptor = null;
+ bool writable;

if (field != null)
{
@@ -125,9 +126,12 @@

if (field.DeclaringType != type &&
field.ReflectedType != type)
throw new ArgumentException(null, "members");
-
- if (!field.IsInitOnly && !field.IsLiteral)
+
+ writable = !field.IsInitOnly;
+ if ((writable || immutable) && !field.IsLiteral)
+ {
descriptor = new TypeFieldDescriptor(field, name);
+ }
}
else
{
@@ -135,7 +139,7 @@

if (property == null)
throw new ArgumentException(null, "members");
-
+
//
// Add public properties that can be read and modified.
// If property is read-only yet has the JsonExport
@@ -150,8 +154,10 @@
if (property.DeclaringType != type &&
property.ReflectedType != type)
throw new ArgumentException(null, "members");

+ writable = property.CanWrite;
+
if ((property.CanRead) &&
- (isAnonymousClass || property.CanWrite ||
property.IsDefined(typeof(JsonExportAttribute), true)) &&
+ (writable || immutable ||
property.IsDefined(typeof(JsonExportAttribute), true)) &&
property.GetIndexParameters().Length == 0)
{
//
@@ -173,6 +179,13 @@
if (descriptor != null)
{
descriptor.ApplyCustomizations();
+
+ if (immutable && writable)
+ {
+ immutable = false;
+ logicalProperties.Clear();
+ }
+
logicalProperties.Add(descriptor);
}

=======================================
--- /tests/Jayrock/Json/Conversion/TestCustomTypeDescriptor.cs Fri Apr 15
16:09:54 2011
+++ /tests/Jayrock/Json/Conversion/TestCustomTypeDescriptor.cs Fri Apr 29
15:29:25 2011
@@ -231,6 +231,16 @@
Assert.AreEqual("Value", property.Name);
Assert.IsTrue(property.IsReadOnly);
}
+
+ [ Test ]
+ public void ImmutableClassPropertiesExpected()
+ {
+ CustomTypeDescriptor descriptor = new
CustomTypeDescriptor(typeof(ImmutableThing));
+ PropertyDescriptorCollection properties =
descriptor.GetProperties();
+ Assert.AreEqual(2, properties.Count);
+ Assert.IsNotNull(properties["field"]);
+ Assert.IsNotNull(properties["property"]);
+ }

private static void AddServiceToServiceContainer(IServiceContainer
sc)
{
@@ -260,6 +270,20 @@
sc.RemoveService(serviceType);
Assert.IsNull(sc.GetService(serviceType));
}
+
+ public sealed class ImmutableThing
+ {
+ public readonly object Field;
+
+ private object _property;
+ public object Property { get { return _property; } }
+
+ public ImmutableThing(object field, object property)
+ {
+ Field = field;
+ _property = property;
+ }
+ }

public sealed class Thing
{

==============================================================================
Revision: f39d1bcbde80
Author: azizatif
Date: Fri Apr 29 15:40:15 2011
Log: Added coverage for backing out of an immutable type definition
http://code.google.com/p/jayrock/source/detail?r=f39d1bcbde80

Modified:
/tests/Jayrock/Json/Conversion/TestCustomTypeDescriptor.cs

=======================================
--- /tests/Jayrock/Json/Conversion/TestCustomTypeDescriptor.cs Fri Apr 29
15:29:25 2011
+++ /tests/Jayrock/Json/Conversion/TestCustomTypeDescriptor.cs Fri Apr 29
15:40:15 2011
@@ -287,10 +287,10 @@

public sealed class Thing
{
+ public readonly object ReadOnlyField = null;
public object Field1;
[ JsonIgnore ] public object Field2;
public object Field3;
- public readonly object ReadOnlyField = null;

public object Property1 { get { return null; } set { } }
[ JsonIgnore ] public object Property2 { get { return null; }
set { } }

Reply all
Reply to author
Forward
0 new messages