-Changed portable assembly to be .NET 4.5, WP8, Win8

This commit is contained in:
James Newton-King
2013-03-31 16:12:52 +13:00
parent 0007006850
commit 77bce8f5de
26 changed files with 163 additions and 191 deletions
@@ -61,7 +61,7 @@ namespace Newtonsoft.Json.Tests
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(1l, reader.Value);
Assert.AreEqual(1L, reader.Value);
Assert.AreEqual(typeof(long), reader.ValueType);
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
@@ -437,7 +437,7 @@ namespace Newtonsoft.Json.Tests.Linq
}
#endif
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
[Test]
public void ConvertsToBoolean()
{
@@ -75,4 +75,4 @@ using System.Security;
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.5.0.0")]
[assembly: AssemblyFileVersion("5.0.1.15930")]
[assembly: AssemblyFileVersion("5.0.1.15931")]
@@ -102,7 +102,7 @@ namespace Newtonsoft.Json.Tests.Serialization
string json = o.ToString();
}
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
[Test]
public void MemberSearchFlags()
{
@@ -182,7 +182,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}", startingWithB);
}
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
[Test]
public void SerializeCompilerGeneratedMembers()
{
@@ -3336,6 +3336,7 @@ To fix this error either change the environment to be fully trusted, change the
}", json);
}
#if !PORTABLE
[Test]
public void DeserializeClassWithInheritedProtectedMember()
{
@@ -3402,6 +3403,7 @@ To fix this error either change the environment to be fully trusted, change the
Assert.AreEqual(3, ReflectionUtils.GetMemberValue(typeof(BB).GetProperty("BB_property7", BindingFlags.Instance | BindingFlags.Public), myB));
Assert.AreEqual(3, ReflectionUtils.GetMemberValue(typeof(BB).GetProperty("BB_property8", BindingFlags.Instance | BindingFlags.Public), myB));
}
#endif
public class AA
{
@@ -6852,7 +6854,8 @@ Parameter name: value",
Assert.AreEqual("[1.1,0.0,0.0]", json);
}
#if !(NET20 || NET35 || NET40 || PORTABLE || SILVERLIGHT)
#if !(NET20 || NET35 || NET40 || SILVERLIGHT)
#if !PORTABLE
[Test]
public void DeserializeReadOnlyListWithBigInteger()
{
@@ -6867,6 +6870,22 @@ Parameter name: value",
Assert.AreEqual(BigInteger.Parse("9000000000000000000000000000000000000000000000000"), nineQuindecillion);
}
#endif
[Test]
public void DeserializeReadOnlyListWithInt()
{
string json = @"[
900
]";
var l = JsonConvert.DeserializeObject<IReadOnlyList<int>>(json);
int i = l[0];
// 900
Assert.AreEqual(900, i);
}
[Test]
public void DeserializeReadOnlyListWithNullableType()
@@ -7833,9 +7852,9 @@ Parameter name: value",
}
#endif
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
[Test]
public void DeserializeReadOnlyList()
public void DeserializeReadOnlyListInterface()
{
IReadOnlyList<int> list = JsonConvert.DeserializeObject<IReadOnlyList<int>>("[1,2,3]");
@@ -7846,7 +7865,7 @@ Parameter name: value",
}
[Test]
public void DeserializeReadOnlyCollection()
public void DeserializeReadOnlyCollectionInterface()
{
IReadOnlyCollection<int> list = JsonConvert.DeserializeObject<IReadOnlyCollection<int>>("[1,2,3]");
@@ -7858,7 +7877,19 @@ Parameter name: value",
}
[Test]
public void DeserializeReadOnlyDictionary()
public void DeserializeReadOnlyCollection()
{
ReadOnlyCollection<int> list = JsonConvert.DeserializeObject<ReadOnlyCollection<int>>("[1,2,3]");
Assert.AreEqual(3, list.Count);
Assert.AreEqual(1, list[0]);
Assert.AreEqual(2, list[1]);
Assert.AreEqual(3, list[2]);
}
[Test]
public void DeserializeReadOnlyDictionaryInterface()
{
IReadOnlyDictionary<string, int> dic = JsonConvert.DeserializeObject<IReadOnlyDictionary<string, int>>("{'one':1,'two':2}");
@@ -7870,6 +7901,17 @@ Parameter name: value",
CustomAssert.IsInstanceOfType(typeof(ReadOnlyDictionary<string, int>), dic);
}
[Test]
public void DeserializeReadOnlyDictionary()
{
ReadOnlyDictionary<string, int> dic = JsonConvert.DeserializeObject<ReadOnlyDictionary<string, int>>("{'one':1,'two':2}");
Assert.AreEqual(2, dic.Count);
Assert.AreEqual(1, dic["one"]);
Assert.AreEqual(2, dic["two"]);
}
public class CustomReadOnlyDictionary<TKey, TValue> : IReadOnlyDictionary<TKey, TValue>
{
private readonly IDictionary<TKey, TValue> _dictionary;
@@ -282,7 +282,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}", json);
}
#if !SILVERLIGHT && !NETFX_CORE
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
public class SerializationEventContextTestObject
{
public string TestMember { get; set; }
@@ -313,6 +313,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}
#endif
#if !PORTABLE
public void WhenSerializationErrorDetectedBySerializer_ThenCallbackIsCalled()
{
// Verify contract is properly finding our callback
@@ -336,7 +337,7 @@ namespace Newtonsoft.Json.Tests.Serialization
// When fixed, this would pass.
Debug.Assert(foo.Identifier == 25);
}
#endif
public class FooEvent
{
public int Identifier { get; set; }
+1 -1
View File
@@ -39,7 +39,7 @@ using System.Text;
#if !NET20 && (!SILVERLIGHT || WINDOWS_PHONE)
using System.Xml.Linq;
#endif
#if NETFX_CORE
#if NETFX_CORE || PORTABLE
using IConvertible = Newtonsoft.Json.Utilities.Convertible;
#endif
+1 -1
View File
@@ -1261,7 +1261,7 @@ namespace Newtonsoft.Json
numberValue = BigInteger.Parse(number, CultureInfo.InvariantCulture);
#else
// todo - validate number was a valid integer to make sure overflow was the reason for failure
throw JsonReaderException.Create((JsonReader)this, "JSON integer {0} is too large or small for an Int64.".FormatWith(CultureInfo.InvariantCulture, number));
throw JsonReaderException.Create(this, "JSON integer {0} is too large or small for an Int64.".FormatWith(CultureInfo.InvariantCulture, number));
#endif
}
+1 -1
View File
@@ -31,7 +31,7 @@ using System.Numerics;
#endif
using Newtonsoft.Json.Utilities;
using System.Globalization;
#if NETFX_CORE
#if NETFX_CORE || PORTABLE
using IConvertible = Newtonsoft.Json.Utilities.Convertible;
#endif
#if NET20
+3 -3
View File
@@ -41,7 +41,7 @@ namespace Newtonsoft.Json.Linq
/// Represents a value in JSON (string, integer, date, etc).
/// </summary>
public class JValue : JToken, IEquatable<JValue>, IFormattable, IComparable, IComparable<JValue>
#if !(NETFX_CORE)
#if !(NETFX_CORE || PORTABLE)
, IConvertible
#endif
{
@@ -919,7 +919,7 @@ namespace Newtonsoft.Json.Linq
return Compare(_valueType, _value, obj._value);
}
#if !(NETFX_CORE)
#if !(NETFX_CORE || PORTABLE)
TypeCode IConvertible.GetTypeCode()
{
if (_value == null)
@@ -929,7 +929,7 @@ namespace Newtonsoft.Json.Linq
if (_value is DateTimeOffset)
return TypeCode.DateTime;
#endif
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
#if !(NET20 || NET35 || SILVERLIGHT)
if (_value is BigInteger)
return TypeCode.Object;
#endif
@@ -8,8 +8,8 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Newtonsoft.Json</RootNamespace>
<AssemblyName>Newtonsoft.Json</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile158</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile78</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
@@ -90,6 +90,6 @@ using System.Security;
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.5.0.0")]
[assembly: AssemblyFileVersion("5.0.1.15930")]
[assembly: AssemblyFileVersion("5.0.1.15931")]
[assembly: CLSCompliant(true)]
@@ -136,7 +136,7 @@ namespace Newtonsoft.Json.Serialization
get { return JsonTypeReflector.DynamicCodeGeneration; }
}
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
/// <summary>
/// Gets or sets the default members search flags.
/// </summary>
@@ -656,11 +656,7 @@ namespace Newtonsoft.Json.Serialization
while (current != null && current != typeof(object))
{
ret.Add(current);
#if NETFX_CORE
current = current.BaseType();
#else
current = current.BaseType;
#endif
}
// Return the class list in order of simple => complex
@@ -55,7 +55,7 @@ namespace Newtonsoft.Json.Serialization
#pragma warning disable 618,612
assembly = Assembly.LoadWithPartialName(assemblyName);
#pragma warning restore 618,612
#elif NETFX_CORE
#elif NETFX_CORE || PORTABLE
assembly = Assembly.Load(new AssemblyName(assemblyName));
#else
assembly = Assembly.Load(assemblyName);
@@ -128,7 +128,7 @@ namespace Newtonsoft.Json.Serialization
/// <param name="typeName">Specifies the <see cref="T:System.Type"/> name of the serialized object. </param>
public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
{
#if NETFX_CORE
#if NETFX_CORE || PORTABLE
assemblyName = serializedType.GetTypeInfo().Assembly.FullName;
typeName = serializedType.FullName;
#elif !SILVERLIGHT
@@ -89,15 +89,6 @@ namespace Newtonsoft.Json.Serialization
canDeserialize = true;
IsMultidimensionalArray = (UnderlyingType.IsArray && UnderlyingType.GetArrayRank() > 1);
}
else if (ReflectionUtils.InheritsGenericDefinition(underlyingType, typeof(ReadOnlyCollection<>), out tempCollectionType))
{
CollectionItemType = tempCollectionType.GetGenericArguments()[0];
ParametrizedConstructor = CollectionUtils.ResolveEnumableCollectionConstructor(underlyingType, CollectionItemType);
IsReadOnlyOrFixedSize = true;
canDeserialize = (ParametrizedConstructor != null);
}
else if (typeof(IList).IsAssignableFrom(underlyingType))
{
if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(ICollection<>), out _genericCollectionDefinitionType))
@@ -129,7 +120,7 @@ namespace Newtonsoft.Json.Serialization
canDeserialize = true;
ShouldCreateWrapper = true;
}
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof (IReadOnlyCollection<>), out tempCollectionType))
{
CollectionItemType = underlyingType.GetGenericArguments()[0];
@@ -195,45 +186,6 @@ namespace Newtonsoft.Json.Serialization
}
internal IWrappedCollection CreateWrapper(object list)
{
if (_genericCollectionDefinitionType != null)
{
EnsureGenericWrapperCreator();
return (IWrappedCollection) _genericWrapperCreator(null, list);
}
else
{
IList values = ((IEnumerable) list).Cast<object>().ToList();
if (CollectionItemType != null)
{
Array array = Array.CreateInstance(CollectionItemType, values.Count);
for (int i = 0; i < values.Count; i++)
{
array.SetValue(values[i], i);
}
values = array;
}
return new CollectionWrapper<object>(values);
}
}
internal IList CreateTemporaryCollection()
{
if (_genericTemporaryCollectionCreator == null)
{
// multidimensional array will also have array instances in it
Type collectionItemType = (IsMultidimensionalArray) ? typeof (object) : CollectionItemType;
Type temporaryListType = ReflectionUtils.MakeGenericType(typeof(List<>), collectionItemType);
_genericTemporaryCollectionCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateDefaultConstructor<object>(temporaryListType);
}
return (IList)_genericTemporaryCollectionCreator();
}
private void EnsureGenericWrapperCreator()
{
if (_genericWrapperCreator == null)
{
@@ -250,6 +202,21 @@ namespace Newtonsoft.Json.Serialization
ConstructorInfo genericWrapperConstructor = _genericWrapperType.GetConstructor(new[] { constructorArgument });
_genericWrapperCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall<object>(genericWrapperConstructor);
}
return (IWrappedCollection) _genericWrapperCreator(null, list);
}
internal IList CreateTemporaryCollection()
{
if (_genericTemporaryCollectionCreator == null)
{
// multidimensional array will also have array instances in it
Type collectionItemType = (IsMultidimensionalArray) ? typeof (object) : CollectionItemType;
Type temporaryListType = ReflectionUtils.MakeGenericType(typeof(List<>), collectionItemType);
_genericTemporaryCollectionCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateDefaultConstructor<object>(temporaryListType);
}
return (IList)_genericTemporaryCollectionCreator();
}
}
}
@@ -91,7 +91,7 @@ namespace Newtonsoft.Json.Serialization
if (ReflectionUtils.IsGenericDefinition(UnderlyingType, typeof(IDictionary<,>)))
CreatedType = ReflectionUtils.MakeGenericType(typeof(Dictionary<,>), keyType, valueType);
}
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(IReadOnlyDictionary<,>), out _genericCollectionDefinitionType))
{
keyType = _genericCollectionDefinitionType.GetGenericArguments()[0];
@@ -114,20 +114,29 @@ namespace Newtonsoft.Json.Serialization
if (keyType != null && valueType != null)
ParametrizedConstructor = CollectionUtils.ResolveEnumableCollectionConstructor(CreatedType, ReflectionUtils.MakeGenericType(typeof(KeyValuePair<,>), keyType, valueType));
ShouldCreateWrapper = !typeof (IDictionary).IsAssignableFrom(underlyingType);
ShouldCreateWrapper = !typeof (IDictionary).IsAssignableFrom(CreatedType);
DictionaryKeyType = keyType;
DictionaryValueType = valueType;
if (DictionaryValueType != null)
_isDictionaryValueTypeNullableType = ReflectionUtils.IsNullableType(DictionaryValueType);
#if (NET20 || NET35)
Type tempDictioanryType;
// bug in .NET 2.0 & 3.5 that Dictionary<TKey, Nullable<TValue>> throws an error when adding null via IDictionary[key] = object
// wrapper will handle calling Add(T) instead
if (_isDictionaryValueTypeNullableType
&& (ReflectionUtils.InheritsGenericDefinition(CreatedType, typeof(Dictionary<,>), out tempDictioanryType)))
{
ShouldCreateWrapper = true;
}
#endif
}
internal IWrappedDictionary CreateWrapper(object dictionary)
{
if (dictionary is IDictionary && (DictionaryValueType == null || !_isDictionaryValueTypeNullableType))
return new DictionaryWrapper<object, object>((IDictionary)dictionary);
if (_genericWrapperCreator == null)
{
_genericWrapperType = ReflectionUtils.MakeGenericType(typeof(DictionaryWrapper<,>), DictionaryKeyType, DictionaryValueType);
@@ -1467,17 +1467,17 @@ To fix this error either change the environment to be fully trusted, change the
}
else if (propertyContract.ContractType == JsonContractType.Dictionary)
{
JsonDictionaryContract jsonDictionaryContract = (JsonDictionaryContract)propertyContract;
JsonDictionaryContract dictionaryContract = (JsonDictionaryContract)propertyContract;
object createdObjectDictionary = property.ValueProvider.GetValue(createdObject);
if (createdObjectDictionary != null)
{
IWrappedDictionary createdObjectDictionaryWrapper = jsonDictionaryContract.CreateWrapper(createdObjectDictionary);
IWrappedDictionary newValues = jsonDictionaryContract.CreateWrapper(value);
IDictionary targetDictionary = (dictionaryContract.ShouldCreateWrapper) ? dictionaryContract.CreateWrapper(createdObjectDictionary) : (IDictionary) createdObjectDictionary;
IDictionary newValues = (dictionaryContract.ShouldCreateWrapper) ? dictionaryContract.CreateWrapper(value) : (IDictionary) value;
foreach (DictionaryEntry newValue in newValues)
{
createdObjectDictionaryWrapper.Add(newValue.Key, newValue.Value);
targetDictionary.Add(newValue.Key, newValue.Value);
}
}
}
@@ -320,7 +320,7 @@ namespace Newtonsoft.Json.Serialization
}
#endif
#if SILVERLIGHT || NETFX_CORE
#if SILVERLIGHT || NETFX_CORE || PORTABLE
if (value is Guid || value is Uri || value is TimeSpan)
{
s = value.ToString();
@@ -106,7 +106,7 @@ namespace Newtonsoft.Json.Utilities
return true;
if (ReflectionUtils.ImplementsGenericDefinition(type, typeof(IDictionary<,>)))
return true;
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
if (ReflectionUtils.ImplementsGenericDefinition(type, typeof(IReadOnlyDictionary<,>)))
return true;
#endif
@@ -38,13 +38,13 @@ using Newtonsoft.Json.Utilities.LinqBridge;
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
using System.Data.SqlTypes;
#endif
#if NETFX_CORE
#if NETFX_CORE || PORTABLE
using IConvertible = Newtonsoft.Json.Utilities.Convertible;
#endif
namespace Newtonsoft.Json.Utilities
{
#if NETFX_CORE
#if NETFX_CORE || PORTABLE
internal class Convertible
{
private object _underlyingValue;
@@ -130,7 +130,7 @@ namespace Newtonsoft.Json.Utilities
{
public static TypeCode GetTypeCode(this IConvertible convertible)
{
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
return convertible.GetTypeCode();
#else
return GetTypeCode((object)convertible);
@@ -148,7 +148,7 @@ namespace Newtonsoft.Json.Utilities
public static TypeCode GetTypeCode(Type t)
{
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
return Type.GetTypeCode(t);
#else
if (t == typeof(bool))
@@ -190,7 +190,7 @@ namespace Newtonsoft.Json.Utilities
public static IConvertible ToConvertible(object o)
{
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
return o as IConvertible;
#else
if (!IsConvertible(o))
@@ -202,7 +202,7 @@ namespace Newtonsoft.Json.Utilities
public static bool IsConvertible(object o)
{
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
return o is IConvertible;
#else
if (o == null)
@@ -216,7 +216,7 @@ namespace Newtonsoft.Json.Utilities
public static bool IsConvertible(Type t)
{
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
return typeof(IConvertible).IsAssignableFrom(t);
#else
return (
@@ -45,7 +45,7 @@ namespace Newtonsoft.Json.Utilities
{
private readonly IDictionary _dictionary;
private readonly IDictionary<TKey, TValue> _genericDictionary;
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
private readonly IReadOnlyDictionary<TKey, TValue> _readOnlyDictionary;
#endif
private object _syncRoot;
@@ -64,7 +64,7 @@ namespace Newtonsoft.Json.Utilities
_genericDictionary = dictionary;
}
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
public DictionaryWrapper(IReadOnlyDictionary<TKey, TValue> dictionary)
{
ValidationUtils.ArgumentNotNull(dictionary, "dictionary");
@@ -87,7 +87,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
return _dictionary.Contains(key);
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
return _readOnlyDictionary.ContainsKey(key);
#endif
@@ -101,7 +101,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
return _dictionary.Keys.Cast<TKey>().ToList();
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
return _readOnlyDictionary.Keys.ToList();
#endif
@@ -124,7 +124,7 @@ namespace Newtonsoft.Json.Utilities
return false;
}
}
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
{
throw new NotSupportedException();
@@ -151,7 +151,7 @@ namespace Newtonsoft.Json.Utilities
return true;
}
}
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
{
throw new NotSupportedException();
@@ -169,7 +169,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
return _dictionary.Values.Cast<TValue>().ToList();
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
return _readOnlyDictionary.Values.ToList();
#endif
@@ -184,7 +184,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
return (TValue)_dictionary[key];
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
return _readOnlyDictionary[key];
#endif
@@ -195,7 +195,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
_dictionary[key] = value;
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
throw new NotSupportedException();
#endif
@@ -208,7 +208,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
((IList)_dictionary).Add(item);
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
throw new NotSupportedException();
#endif
@@ -220,7 +220,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
_dictionary.Clear();
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
throw new NotSupportedException();
#endif
@@ -232,7 +232,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
return ((IList)_dictionary).Contains(item);
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
return _readOnlyDictionary.Contains(item);
#endif
@@ -249,7 +249,7 @@ namespace Newtonsoft.Json.Utilities
array[arrayIndex++] = new KeyValuePair<TKey, TValue>((TKey)item.Key, (TValue)item.Value);
}
}
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
{
throw new NotSupportedException();
@@ -267,7 +267,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
return _dictionary.Count;
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
return _readOnlyDictionary.Count;
#endif
@@ -282,7 +282,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
return _dictionary.IsReadOnly;
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
return true;
#endif
@@ -314,7 +314,7 @@ namespace Newtonsoft.Json.Utilities
return true;
}
}
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
{
throw new NotSupportedException();
@@ -330,7 +330,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
return _dictionary.Cast<DictionaryEntry>().Select(de => new KeyValuePair<TKey, TValue>((TKey)de.Key, (TValue)de.Value)).GetEnumerator();
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
return _readOnlyDictionary.GetEnumerator();
#endif
@@ -347,7 +347,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
_dictionary.Add(key, value);
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
throw new NotSupportedException();
#endif
@@ -361,7 +361,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
return _dictionary[key];
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
return _readOnlyDictionary[(TKey)key];
#endif
@@ -372,7 +372,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
_dictionary[key] = value;
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
throw new NotSupportedException();
#endif
@@ -426,7 +426,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
return _dictionary.GetEnumerator();
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
return new DictionaryEnumerator<TKey, TValue>(_readOnlyDictionary.GetEnumerator());
#endif
@@ -438,7 +438,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_genericDictionary != null)
return _genericDictionary.ContainsKey((TKey)key);
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
return _readOnlyDictionary.ContainsKey((TKey)key);
#endif
@@ -452,7 +452,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_genericDictionary != null)
return false;
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
return true;
#endif
@@ -467,7 +467,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_genericDictionary != null)
return _genericDictionary.Keys.ToList();
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
return _readOnlyDictionary.Keys.ToList();
#endif
@@ -480,7 +480,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
_dictionary.Remove(key);
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
throw new NotSupportedException();
#endif
@@ -494,7 +494,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_genericDictionary != null)
return _genericDictionary.Values.ToList();
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
return _readOnlyDictionary.Values.ToList();
#endif
@@ -507,7 +507,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
_dictionary.CopyTo(array, index);
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
throw new NotSupportedException();
#endif
@@ -543,7 +543,7 @@ namespace Newtonsoft.Json.Utilities
{
if (_dictionary != null)
return _dictionary;
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
else if (_readOnlyDictionary != null)
return _readOnlyDictionary;
#endif
@@ -72,7 +72,7 @@ namespace Newtonsoft.Json.Utilities
}
#endif
#if NETFX_CORE
#if (NETFX_CORE || PORTABLE)
internal enum TypeCode
{
Empty,
@@ -721,18 +721,12 @@ namespace Newtonsoft.Json.Utilities
return (attributes != null) ? attributes.SingleOrDefault() : null;
}
#if !(NETFX_CORE)
#if !(NETFX_CORE || PORTABLE)
public static T[] GetAttributes<T>(ICustomAttributeProvider attributeProvider, bool inherit) where T : Attribute
{
ValidationUtils.ArgumentNotNull(attributeProvider, "attributeProvider");
object provider;
#if !PORTABLE
provider = attributeProvider;
#else
provider = attributeProvider.UnderlyingObject;
#endif
object provider = attributeProvider;
// http://hyperthink.net/blog/getcustomattributes-gotcha/
// ICustomAttributeProvider doesn't do inheritance
@@ -746,19 +740,13 @@ namespace Newtonsoft.Json.Utilities
if (provider is MemberInfo)
return (T[])Attribute.GetCustomAttributes((MemberInfo)provider, typeof(T), inherit);
#if !PORTABLE
if (provider is Module)
return (T[])Attribute.GetCustomAttributes((Module)provider, typeof(T), inherit);
#endif
if (provider is ParameterInfo)
return (T[])Attribute.GetCustomAttributes((ParameterInfo)provider, typeof(T), inherit);
#if !PORTABLE
return (T[])attributeProvider.GetCustomAttributes(typeof(T), inherit);
#else
throw new Exception("Cannot get attributes from '{0}'.".FormatWith(CultureInfo.InvariantCulture, provider));
#endif
}
#else
public static T[] GetAttributes<T>(ICustomAttributeProvider attributeProvider, bool inherit) where T : Attribute
@@ -886,7 +874,7 @@ namespace Newtonsoft.Json.Utilities
ValidationUtils.ArgumentNotNull(targetType, "targetType");
List<MemberInfo> fieldInfos = new List<MemberInfo>(targetType.GetFields(bindingAttr));
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
// Type.GetFields doesn't return inherited private fields
// manually find private fields from base class
GetChildPrivateFields(fieldInfos, targetType, bindingAttr);
@@ -984,10 +972,7 @@ namespace Newtonsoft.Json.Utilities
info.Name == method &&
// check that the method overrides the original on DynamicObjectProxy
info.DeclaringType != methodDeclaringType
// todo - find out whether there is a way to do this in winrt
#if !NETFX_CORE
&& info.GetBaseDefinition().DeclaringType == methodDeclaringType
#endif
);
return isMethodOverriden;
+1 -1
View File
@@ -162,7 +162,7 @@ namespace Newtonsoft.Json.Utilities
if ((i == 0 || !hasNext) || char.IsUpper(s[i + 1]))
{
char lowerCase;
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
lowerCase = char.ToLower(s[i], CultureInfo.InvariantCulture);
#else
lowerCase = char.ToLower(s[i]);
@@ -78,7 +78,7 @@ namespace Newtonsoft.Json.Utilities
Dictionary<TKey, TValue> newStore = new Dictionary<TKey, TValue>(_store);
newStore[key] = value;
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
Thread.MemoryBarrier();
#endif
_store = newStore;
+19 -47
View File
@@ -36,7 +36,7 @@ namespace Newtonsoft.Json.Utilities
{
internal static class TypeExtensions
{
#if NETFX_CORE
#if NETFX_CORE || PORTABLE
private static BindingFlags DefaultFlags = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
public static MethodInfo GetGetMethod(this PropertyInfo propertyInfo)
@@ -80,10 +80,10 @@ namespace Newtonsoft.Json.Utilities
public static MethodInfo Method(this Delegate d)
{
#if NETFX_CORE
return d.GetMethodInfo();
#else
#if !(NETFX_CORE || PORTABLE)
return d.Method;
#else
return d.GetMethodInfo();
#endif
}
@@ -107,7 +107,7 @@ namespace Newtonsoft.Json.Utilities
public static bool ContainsGenericParameters(this Type type)
{
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
return type.ContainsGenericParameters;
#else
return type.GetTypeInfo().ContainsGenericParameters;
@@ -116,7 +116,7 @@ namespace Newtonsoft.Json.Utilities
public static bool IsInterface(this Type type)
{
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
return type.IsInterface;
#else
return type.GetTypeInfo().IsInterface;
@@ -125,7 +125,7 @@ namespace Newtonsoft.Json.Utilities
public static bool IsGenericType(this Type type)
{
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
return type.IsGenericType;
#else
return type.GetTypeInfo().IsGenericType;
@@ -134,7 +134,7 @@ namespace Newtonsoft.Json.Utilities
public static bool IsGenericTypeDefinition(this Type type)
{
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
return type.IsGenericTypeDefinition;
#else
return type.GetTypeInfo().IsGenericTypeDefinition;
@@ -143,7 +143,7 @@ namespace Newtonsoft.Json.Utilities
public static Type BaseType(this Type type)
{
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
return type.BaseType;
#else
return type.GetTypeInfo().BaseType;
@@ -152,7 +152,7 @@ namespace Newtonsoft.Json.Utilities
public static bool IsEnum(this Type type)
{
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
return type.IsEnum;
#else
return type.GetTypeInfo().IsEnum;
@@ -161,7 +161,7 @@ namespace Newtonsoft.Json.Utilities
public static bool IsClass(this Type type)
{
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
return type.IsClass;
#else
return type.GetTypeInfo().IsClass;
@@ -170,49 +170,21 @@ namespace Newtonsoft.Json.Utilities
public static bool IsSealed(this Type type)
{
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
return type.IsSealed;
#else
return type.GetTypeInfo().IsSealed;
#endif
}
#if PORTABLE
public static PropertyInfo GetProperty(this Type type, string name, BindingFlags bindingFlags, object placeholder1, Type propertyType, IList<Type> indexParameters, object placeholder2)
#if (NETFX_CORE || PORTABLE)
public static MethodInfo GetBaseDefinition(this MethodInfo method)
{
IList<PropertyInfo> propertyInfos = type.GetProperties(bindingFlags);
return propertyInfos.Where(p =>
{
if (name != null && name != p.Name)
return false;
if (propertyType != null && propertyType != p.PropertyType)
return false;
if (indexParameters != null)
{
if (!p.GetIndexParameters().Select(ip => ip.ParameterType).SequenceEqual(indexParameters))
return false;
}
return true;
}).SingleOrDefault();
}
public static IEnumerable<MemberInfo> GetMember(this Type type, string name, MemberTypes memberType, BindingFlags bindingFlags)
{
return type.GetMembers(bindingFlags).Where(m =>
{
if (name != null && name != m.Name)
return false;
if (m.MemberType() != memberType)
return false;
return true;
});
return method.GetRuntimeBaseDefinition();
}
#endif
#if NETFX_CORE
#if (NETFX_CORE || PORTABLE)
public static bool IsDefined(this Type type, Type attributeType, bool inherit)
{
return type.GetTypeInfo().CustomAttributes.Any(a => a.AttributeType == attributeType);
@@ -489,7 +461,7 @@ namespace Newtonsoft.Json.Utilities
public static bool IsAbstract(this Type type)
{
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
return type.IsAbstract;
#else
return type.GetTypeInfo().IsAbstract;
@@ -498,7 +470,7 @@ namespace Newtonsoft.Json.Utilities
public static bool IsVisible(this Type type)
{
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
return type.IsVisible;
#else
return type.GetTypeInfo().IsVisible;
@@ -507,7 +479,7 @@ namespace Newtonsoft.Json.Utilities
public static bool IsValueType(this Type type)
{
#if !NETFX_CORE
#if !(NETFX_CORE || PORTABLE)
return type.IsValueType;
#else
return type.GetTypeInfo().IsValueType;