diff --git a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs index 6eea9951..67049d85 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs @@ -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); diff --git a/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs index 7b43ad6b..4d2f36cf 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs @@ -437,7 +437,7 @@ namespace Newtonsoft.Json.Tests.Linq } #endif -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) [Test] public void ConvertsToBoolean() { diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs index 634c0c70..55289ad3 100644 --- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Src/Newtonsoft.Json.Tests/Serialization/CamelCasePropertyNamesContractResolverTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/CamelCasePropertyNamesContractResolverTests.cs index 70dacaa0..0fffcc10 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/CamelCasePropertyNamesContractResolverTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/CamelCasePropertyNamesContractResolverTests.cs @@ -102,7 +102,7 @@ namespace Newtonsoft.Json.Tests.Serialization string json = o.ToString(); } -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) [Test] public void MemberSearchFlags() { diff --git a/Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs index d432931c..eb98a2b7 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs @@ -182,7 +182,7 @@ namespace Newtonsoft.Json.Tests.Serialization }", startingWithB); } -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) [Test] public void SerializeCompilerGeneratedMembers() { diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index d97c5f4f..42259ace 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -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>(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 list = JsonConvert.DeserializeObject>("[1,2,3]"); @@ -7846,7 +7865,7 @@ Parameter name: value", } [Test] - public void DeserializeReadOnlyCollection() + public void DeserializeReadOnlyCollectionInterface() { IReadOnlyCollection list = JsonConvert.DeserializeObject>("[1,2,3]"); @@ -7858,7 +7877,19 @@ Parameter name: value", } [Test] - public void DeserializeReadOnlyDictionary() + public void DeserializeReadOnlyCollection() + { + ReadOnlyCollection list = JsonConvert.DeserializeObject>("[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 dic = JsonConvert.DeserializeObject>("{'one':1,'two':2}"); @@ -7870,6 +7901,17 @@ Parameter name: value", CustomAssert.IsInstanceOfType(typeof(ReadOnlyDictionary), dic); } + [Test] + public void DeserializeReadOnlyDictionary() + { + ReadOnlyDictionary dic = JsonConvert.DeserializeObject>("{'one':1,'two':2}"); + + Assert.AreEqual(2, dic.Count); + + Assert.AreEqual(1, dic["one"]); + Assert.AreEqual(2, dic["two"]); + } + public class CustomReadOnlyDictionary : IReadOnlyDictionary { private readonly IDictionary _dictionary; diff --git a/Src/Newtonsoft.Json.Tests/Serialization/SerializationEventAttributeTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/SerializationEventAttributeTests.cs index 21f430ad..dc57a47d 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/SerializationEventAttributeTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/SerializationEventAttributeTests.cs @@ -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; } diff --git a/Src/Newtonsoft.Json/JsonConvert.cs b/Src/Newtonsoft.Json/JsonConvert.cs index 2b66c7d4..f58842fc 100644 --- a/Src/Newtonsoft.Json/JsonConvert.cs +++ b/Src/Newtonsoft.Json/JsonConvert.cs @@ -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 diff --git a/Src/Newtonsoft.Json/JsonTextReader.cs b/Src/Newtonsoft.Json/JsonTextReader.cs index d4c2840f..ab4d9196 100644 --- a/Src/Newtonsoft.Json/JsonTextReader.cs +++ b/Src/Newtonsoft.Json/JsonTextReader.cs @@ -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 } diff --git a/Src/Newtonsoft.Json/JsonWriter.cs b/Src/Newtonsoft.Json/JsonWriter.cs index f27d6112..38a309e1 100644 --- a/Src/Newtonsoft.Json/JsonWriter.cs +++ b/Src/Newtonsoft.Json/JsonWriter.cs @@ -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 diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs index bd193600..264a1130 100644 --- a/Src/Newtonsoft.Json/Linq/JValue.cs +++ b/Src/Newtonsoft.Json/Linq/JValue.cs @@ -41,7 +41,7 @@ namespace Newtonsoft.Json.Linq /// Represents a value in JSON (string, integer, date, etc). /// public class JValue : JToken, IEquatable, IFormattable, IComparable, IComparable -#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 diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj index 183a51d9..63baf38c 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj @@ -8,8 +8,8 @@ Properties Newtonsoft.Json Newtonsoft.Json - v4.0 - Profile158 + v4.5 + Profile78 512 {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10.0 diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index 2f9bf83f..52274148 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -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)] diff --git a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs index 864e0229..fd8a1df3 100644 --- a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs +++ b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs @@ -136,7 +136,7 @@ namespace Newtonsoft.Json.Serialization get { return JsonTypeReflector.DynamicCodeGeneration; } } -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) /// /// Gets or sets the default members search flags. /// @@ -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 diff --git a/Src/Newtonsoft.Json/Serialization/DefaultSerializationBinder.cs b/Src/Newtonsoft.Json/Serialization/DefaultSerializationBinder.cs index ed1c9043..3ce9000f 100644 --- a/Src/Newtonsoft.Json/Serialization/DefaultSerializationBinder.cs +++ b/Src/Newtonsoft.Json/Serialization/DefaultSerializationBinder.cs @@ -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 /// Specifies the name of the serialized object. 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 diff --git a/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs b/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs index d5bbfa11..12aaaac1 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs @@ -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().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(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(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(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(temporaryListType); + } + + return (IList)_genericTemporaryCollectionCreator(); } } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs b/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs index 73753d1a..3bde0bde 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs @@ -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> 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((IDictionary)dictionary); - if (_genericWrapperCreator == null) { _genericWrapperType = ReflectionUtils.MakeGenericType(typeof(DictionaryWrapper<,>), DictionaryKeyType, DictionaryValueType); diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs index e06a220f..bfc9aeb3 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs @@ -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); } } } diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs index df6291b7..02b9d0c9 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs @@ -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(); diff --git a/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs b/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs index 0ca49188..d71ab96c 100644 --- a/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs @@ -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 diff --git a/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs b/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs index f03aab77..55c539e1 100644 --- a/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs @@ -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 ( diff --git a/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs b/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs index 4d54714c..699b0fba 100644 --- a/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs +++ b/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs @@ -45,7 +45,7 @@ namespace Newtonsoft.Json.Utilities { private readonly IDictionary _dictionary; private readonly IDictionary _genericDictionary; -#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE) +#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE) private readonly IReadOnlyDictionary _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 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().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().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)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().Select(de => new KeyValuePair((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(_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 diff --git a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs index 0e00cc8e..8d39e71f 100644 --- a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs @@ -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(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(ICustomAttributeProvider attributeProvider, bool inherit) where T : Attribute @@ -886,7 +874,7 @@ namespace Newtonsoft.Json.Utilities ValidationUtils.ArgumentNotNull(targetType, "targetType"); List fieldInfos = new List(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; diff --git a/Src/Newtonsoft.Json/Utilities/StringUtils.cs b/Src/Newtonsoft.Json/Utilities/StringUtils.cs index b1438c80..4f89601a 100644 --- a/Src/Newtonsoft.Json/Utilities/StringUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/StringUtils.cs @@ -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]); diff --git a/Src/Newtonsoft.Json/Utilities/ThreadSafeStore.cs b/Src/Newtonsoft.Json/Utilities/ThreadSafeStore.cs index 95fd469a..dbd0a96f 100644 --- a/Src/Newtonsoft.Json/Utilities/ThreadSafeStore.cs +++ b/Src/Newtonsoft.Json/Utilities/ThreadSafeStore.cs @@ -78,7 +78,7 @@ namespace Newtonsoft.Json.Utilities Dictionary newStore = new Dictionary(_store); newStore[key] = value; -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) Thread.MemoryBarrier(); #endif _store = newStore; diff --git a/Src/Newtonsoft.Json/Utilities/TypeExtensions.cs b/Src/Newtonsoft.Json/Utilities/TypeExtensions.cs index 5d92f745..1f79e967 100644 --- a/Src/Newtonsoft.Json/Utilities/TypeExtensions.cs +++ b/Src/Newtonsoft.Json/Utilities/TypeExtensions.cs @@ -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 indexParameters, object placeholder2) +#if (NETFX_CORE || PORTABLE) + public static MethodInfo GetBaseDefinition(this MethodInfo method) { - IList 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 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;