Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/Newtonsoft.Json.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/Src
diff options
context:
space:
mode:
authorJamesNK <james@newtonking.com>2011-02-24 04:46:00 +0300
committerJamesNK <james@newtonking.com>2011-02-24 04:46:00 +0300
commit1824aa4b59f2b81ecd0c0d9ad52676e1b8aa8f64 (patch)
tree5260d0755d631b7ca2fea1034741e3c2888f47b9 /Src
parent05a4395a949d5a4a1347f85eaa9162852e21272e (diff)
-Fixed duplicate type name within an assembly error
Diffstat (limited to 'Src')
-rw-r--r--Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs1
-rw-r--r--Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs24
-rw-r--r--Src/Newtonsoft.Json/Linq/JValue.cs36
-rw-r--r--Src/Newtonsoft.Json/Utilities/DynamicWrapper.cs12
4 files changed, 62 insertions, 11 deletions
diff --git a/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs
index fd3c1f8..02ac0a4 100644
--- a/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs
@@ -8,6 +8,7 @@ using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.Formatters;
using System.Text;
+using Newtonsoft.Json.Tests.TestObjects;
using Newtonsoft.Json.Utilities;
using NUnit.Framework;
diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs
index 38c85ba..e2502b6 100644
--- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs
+++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs
@@ -4154,5 +4154,29 @@ keyword such as type of business.""
Assert.AreEqual("Two", c2.Enumerable.ElementAt(1));
Assert.AreEqual("Three", c2.Enumerable.ElementAt(2));
}
+
+ [JsonObject(MemberSerialization.OptIn)]
+ public class ItemBase
+ {
+ [JsonProperty]
+ public string Name { get; set; }
+ }
+
+ public class ComplexItem : ItemBase
+ {
+ public Stream Source { get; set; }
+ }
+
+ [Test]
+ public void SerializeAttributesOnBase()
+ {
+ ComplexItem i = new ComplexItem();
+
+ string json = JsonConvert.SerializeObject(i, Formatting.Indented);
+
+ Assert.AreEqual(@"{
+ ""Name"": null
+}", json);
+ }
}
} \ No newline at end of file
diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs
index 7da7678..9f89a62 100644
--- a/Src/Newtonsoft.Json/Linq/JValue.cs
+++ b/Src/Newtonsoft.Json/Linq/JValue.cs
@@ -167,20 +167,20 @@ namespace Newtonsoft.Json.Linq
case JTokenType.Comment:
case JTokenType.String:
case JTokenType.Raw:
- string s1 = Convert.ToString(objA);
- string s2 = Convert.ToString(objB);
+ string s1 = Convert.ToString(objA, CultureInfo.InvariantCulture);
+ string s2 = Convert.ToString(objB, CultureInfo.InvariantCulture);
return s1.CompareTo(s2);
case JTokenType.Boolean:
- bool b1 = Convert.ToBoolean(objA);
- bool b2 = Convert.ToBoolean(objB);
+ bool b1 = Convert.ToBoolean(objA, CultureInfo.InvariantCulture);
+ bool b2 = Convert.ToBoolean(objB, CultureInfo.InvariantCulture);
return b1.CompareTo(b2);
case JTokenType.Date:
if (objA is DateTime)
{
- DateTime date1 = Convert.ToDateTime(objA);
- DateTime date2 = Convert.ToDateTime(objB);
+ DateTime date1 = Convert.ToDateTime(objA, CultureInfo.InvariantCulture);
+ DateTime date2 = Convert.ToDateTime(objB, CultureInfo.InvariantCulture);
return date1.CompareTo(date2);
}
@@ -555,12 +555,30 @@ namespace Newtonsoft.Json.Linq
return Compare(_valueType, _value, otherValue);
}
- public int CompareTo(JValue other)
+ /// <summary>
+ /// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
+ /// </summary>
+ /// <param name="obj">An object to compare with this instance.</param>
+ /// <returns>
+ /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:
+ /// Value
+ /// Meaning
+ /// Less than zero
+ /// This instance is less than <paramref name="obj"/>.
+ /// Zero
+ /// This instance is equal to <paramref name="obj"/>.
+ /// Greater than zero
+ /// This instance is greater than <paramref name="obj"/>.
+ /// </returns>
+ /// <exception cref="T:System.ArgumentException">
+ /// <paramref name="obj"/> is not the same type as this instance.
+ /// </exception>
+ public int CompareTo(JValue obj)
{
- if (other == null)
+ if (obj == null)
return 1;
- return Compare(_valueType, _value, other._value);
+ return Compare(_valueType, _value, obj._value);
}
}
} \ No newline at end of file
diff --git a/Src/Newtonsoft.Json/Utilities/DynamicWrapper.cs b/Src/Newtonsoft.Json/Utilities/DynamicWrapper.cs
index 8e88819..0df9f4a 100644
--- a/Src/Newtonsoft.Json/Utilities/DynamicWrapper.cs
+++ b/Src/Newtonsoft.Json/Utilities/DynamicWrapper.cs
@@ -79,8 +79,16 @@ namespace Newtonsoft.Json.Utilities
if (wrapperType == null)
{
- wrapperType = GenerateWrapperType(interfaceType, realObjectType);
- _wrapperDictionary.SetType(interfaceType, realObjectType, wrapperType);
+ lock (_lock)
+ {
+ wrapperType = _wrapperDictionary.GetType(interfaceType, realObjectType);
+
+ if (wrapperType == null)
+ {
+ wrapperType = GenerateWrapperType(interfaceType, realObjectType);
+ _wrapperDictionary.SetType(interfaceType, realObjectType, wrapperType);
+ }
+ }
}
return wrapperType;