diff --git a/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs index c73f1527..a5d6d743 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs @@ -121,11 +121,13 @@ namespace Newtonsoft.Json.Tests.Serialization string json = JsonConvert.SerializeObject(o, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, +#pragma warning disable 618 TypeNameAssemblyFormat = FormatterAssemblyStyle.Full +#pragma warning restore 618 }); - string dynamicChildObjectTypeName = ReflectionUtils.GetTypeName(typeof(DynamicChildObject), FormatterAssemblyStyle.Full, null); - string expandoObjectTypeName = ReflectionUtils.GetTypeName(typeof(ExpandoObject), FormatterAssemblyStyle.Full, null); + string dynamicChildObjectTypeName = ReflectionUtils.GetTypeName(typeof(DynamicChildObject), TypeNameAssemblyFormatHandling.Full, null); + string expandoObjectTypeName = ReflectionUtils.GetTypeName(typeof(ExpandoObject), TypeNameAssemblyFormatHandling.Full, null); StringAssert.AreEqual(@"{ ""$type"": """ + expandoObjectTypeName + @""", @@ -141,7 +143,9 @@ namespace Newtonsoft.Json.Tests.Serialization dynamic n = JsonConvert.DeserializeObject(json, null, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, +#pragma warning disable 618 TypeNameAssemblyFormat = FormatterAssemblyStyle.Full +#pragma warning restore 618 }); CustomAssert.IsInstanceOfType(typeof(ExpandoObject), n); diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index 13c51028..10167933 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -1259,10 +1259,22 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(traceWriter, serializer.TraceWriter); #if !(PORTABLE || PORTABLE40 || NETFX_CORE || NET20 || DNXCORE50) +#pragma warning disable 618 serializer.TypeNameAssemblyFormat = FormatterAssemblyStyle.Full; Assert.AreEqual(FormatterAssemblyStyle.Full, serializer.TypeNameAssemblyFormat); +#pragma warning restore 618 + + Assert.AreEqual(TypeNameAssemblyFormatHandling.Full, serializer.TypeNameAssemblyFormatHandling); + + serializer.TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple; +#pragma warning disable 618 + Assert.AreEqual(FormatterAssemblyStyle.Simple, serializer.TypeNameAssemblyFormat); +#pragma warning restore 618 #endif + serializer.TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Full; + Assert.AreEqual(TypeNameAssemblyFormatHandling.Full, serializer.TypeNameAssemblyFormatHandling); + serializer.TypeNameHandling = TypeNameHandling.All; Assert.AreEqual(TypeNameHandling.All, serializer.TypeNameHandling); } @@ -1360,10 +1372,22 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(traceWriter, settings.TraceWriter); #if !(PORTABLE || PORTABLE40 || NETFX_CORE || NET20 || DNXCORE50) +#pragma warning disable 618 settings.TypeNameAssemblyFormat = FormatterAssemblyStyle.Full; Assert.AreEqual(FormatterAssemblyStyle.Full, settings.TypeNameAssemblyFormat); +#pragma warning restore 618 + + Assert.AreEqual(TypeNameAssemblyFormatHandling.Full, settings.TypeNameAssemblyFormatHandling); + + settings.TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple; +#pragma warning disable 618 + Assert.AreEqual(FormatterAssemblyStyle.Simple, settings.TypeNameAssemblyFormat); +#pragma warning restore 618 #endif + settings.TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Full; + Assert.AreEqual(TypeNameAssemblyFormatHandling.Full, settings.TypeNameAssemblyFormatHandling); + settings.TypeNameHandling = TypeNameHandling.All; Assert.AreEqual(TypeNameHandling.All, settings.TypeNameHandling); } @@ -1455,10 +1479,22 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(traceWriter, serializerProxy.TraceWriter); #if !(PORTABLE || PORTABLE40 || NETFX_CORE || NET20 || DNXCORE50) +#pragma warning disable 618 serializerProxy.TypeNameAssemblyFormat = FormatterAssemblyStyle.Full; Assert.AreEqual(FormatterAssemblyStyle.Full, serializerProxy.TypeNameAssemblyFormat); +#pragma warning restore 618 + + Assert.AreEqual(TypeNameAssemblyFormatHandling.Full, serializerProxy.TypeNameAssemblyFormatHandling); + + serializerProxy.TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple; +#pragma warning disable 618 + Assert.AreEqual(FormatterAssemblyStyle.Simple, serializerProxy.TypeNameAssemblyFormat); +#pragma warning restore 618 #endif + serializerProxy.TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Full; + Assert.AreEqual(TypeNameAssemblyFormatHandling.Full, serializerProxy.TypeNameAssemblyFormatHandling); + serializerProxy.TypeNameHandling = TypeNameHandling.All; Assert.AreEqual(TypeNameHandling.All, serializerProxy.TypeNameHandling); } diff --git a/Src/Newtonsoft.Json.Tests/Serialization/MetadataPropertyHandlingTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/MetadataPropertyHandlingTests.cs index b615a355..2317362f 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/MetadataPropertyHandlingTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/MetadataPropertyHandlingTests.cs @@ -376,7 +376,9 @@ namespace Newtonsoft.Json.Tests.Serialization List values = (List)JsonConvert.DeserializeObject(json, typeof(List), new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects, +#pragma warning disable 618 TypeNameAssemblyFormat = FormatterAssemblyStyle.Full, +#pragma warning restore 618 MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead }); @@ -399,7 +401,7 @@ namespace Newtonsoft.Json.Tests.Serialization [Test] public void WriteListTypeNameForProperty() { - string listRef = ReflectionUtils.GetTypeName(typeof(List), FormatterAssemblyStyle.Simple, null); + string listRef = ReflectionUtils.GetTypeName(typeof(List), TypeNameAssemblyFormatHandling.Simple, null); TypeNameHandlingTests.TypeNameProperty typeNameProperty = new TypeNameHandlingTests.TypeNameProperty { diff --git a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs index fb901669..988933ba 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs @@ -322,7 +322,7 @@ namespace Newtonsoft.Json.Tests.Serialization [Test] public void WriteTypeNameForObjects() { - string employeeRef = ReflectionUtils.GetTypeName(typeof(EmployeeReference), FormatterAssemblyStyle.Simple, null); + string employeeRef = ReflectionUtils.GetTypeName(typeof(EmployeeReference), TypeNameAssemblyFormatHandling.Simple, null); EmployeeReference employee = new EmployeeReference(); @@ -342,7 +342,7 @@ namespace Newtonsoft.Json.Tests.Serialization [Test] public void DeserializeTypeName() { - string employeeRef = ReflectionUtils.GetTypeName(typeof(EmployeeReference), FormatterAssemblyStyle.Simple, null); + string employeeRef = ReflectionUtils.GetTypeName(typeof(EmployeeReference), TypeNameAssemblyFormatHandling.Simple, null); string json = @"{ ""$id"": ""1"", @@ -364,7 +364,7 @@ namespace Newtonsoft.Json.Tests.Serialization [Test] public void DeserializeTypeNameFromGacAssembly() { - string cookieRef = ReflectionUtils.GetTypeName(typeof(Cookie), FormatterAssemblyStyle.Simple, null); + string cookieRef = ReflectionUtils.GetTypeName(typeof(Cookie), TypeNameAssemblyFormatHandling.Simple, null); string json = @"{ ""$id"": ""1"", @@ -406,7 +406,9 @@ namespace Newtonsoft.Json.Tests.Serialization string json = JsonConvert.SerializeObject(values, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects, +#pragma warning disable 618 TypeNameAssemblyFormat = FormatterAssemblyStyle.Full +#pragma warning restore 618 }); StringAssert.AreEqual(@"[ @@ -463,7 +465,9 @@ namespace Newtonsoft.Json.Tests.Serialization List values = (List)JsonConvert.DeserializeObject(json, typeof(List), new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects, +#pragma warning disable 618 TypeNameAssemblyFormat = FormatterAssemblyStyle.Full +#pragma warning restore 618 }); Assert.AreEqual(4, values.Count); @@ -500,7 +504,9 @@ namespace Newtonsoft.Json.Tests.Serialization JsonConvert.DeserializeObject(json, typeof(Person), new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects, +#pragma warning disable 618 TypeNameAssemblyFormat = FormatterAssemblyStyle.Full +#pragma warning restore 618 }); } catch (JsonSerializationException ex) @@ -593,7 +599,9 @@ namespace Newtonsoft.Json.Tests.Serialization ICorrelatedMessage message = JsonConvert.DeserializeObject(json, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects, +#pragma warning disable 618 TypeNameAssemblyFormat = FormatterAssemblyStyle.Full +#pragma warning restore 618 }); CustomAssert.IsInstanceOfType(typeof(SendHttpRequest), message); @@ -621,7 +629,9 @@ namespace Newtonsoft.Json.Tests.Serialization { NullValueHandling = NullValueHandling.Ignore, TypeNameHandling = TypeNameHandling.All, +#pragma warning disable 618 TypeNameAssemblyFormat = FormatterAssemblyStyle.Full +#pragma warning restore 618 }); StringAssert.AreEqual(@"{ @@ -648,7 +658,7 @@ namespace Newtonsoft.Json.Tests.Serialization [Test] public void WriteObjectTypeNameForProperty() { - string typeNamePropertyRef = ReflectionUtils.GetTypeName(typeof(TypeNameProperty), FormatterAssemblyStyle.Simple, null); + string typeNamePropertyRef = ReflectionUtils.GetTypeName(typeof(TypeNameProperty), TypeNameAssemblyFormatHandling.Simple, null); TypeNameProperty typeNameProperty = new TypeNameProperty { @@ -682,7 +692,7 @@ namespace Newtonsoft.Json.Tests.Serialization [Test] public void WriteListTypeNameForProperty() { - string listRef = ReflectionUtils.GetTypeName(typeof(List), FormatterAssemblyStyle.Simple, null); + string listRef = ReflectionUtils.GetTypeName(typeof(List), TypeNameAssemblyFormatHandling.Simple, null); TypeNameProperty typeNameProperty = new TypeNameProperty { @@ -863,9 +873,9 @@ namespace Newtonsoft.Json.Tests.Serialization string json = sw.ToString(); - string contentSubClassRef = ReflectionUtils.GetTypeName(typeof(ContentSubClass), FormatterAssemblyStyle.Simple, null); - string dictionaryRef = ReflectionUtils.GetTypeName(typeof(Dictionary>), FormatterAssemblyStyle.Simple, null); - string listRef = ReflectionUtils.GetTypeName(typeof(List), FormatterAssemblyStyle.Simple, null); + string contentSubClassRef = ReflectionUtils.GetTypeName(typeof(ContentSubClass), TypeNameAssemblyFormatHandling.Simple, null); + string dictionaryRef = ReflectionUtils.GetTypeName(typeof(Dictionary>), TypeNameAssemblyFormatHandling.Simple, null); + string listRef = ReflectionUtils.GetTypeName(typeof(List), TypeNameAssemblyFormatHandling.Simple, null); string expected = @"{ ""TestMember"": { @@ -966,10 +976,12 @@ namespace Newtonsoft.Json.Tests.Serialization string json = JsonConvert.SerializeObject(collection, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, +#pragma warning disable 618 TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple +#pragma warning restore 618 }); - string urlStatusTypeName = ReflectionUtils.GetTypeName(typeof(UrlStatus), FormatterAssemblyStyle.Simple, null); + string urlStatusTypeName = ReflectionUtils.GetTypeName(typeof(UrlStatus), TypeNameAssemblyFormatHandling.Simple, null); StringAssert.AreEqual(@"{ ""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib"", @@ -1003,7 +1015,9 @@ namespace Newtonsoft.Json.Tests.Serialization object c = JsonConvert.DeserializeObject(json, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, +#pragma warning disable 618 TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple +#pragma warning restore 618 }); CustomAssert.IsInstanceOfType(typeof(Dictionary), c); @@ -1019,7 +1033,7 @@ namespace Newtonsoft.Json.Tests.Serialization [Test] public void SerializingIEnumerableOfTShouldRetainGenericTypeInfo() { - string productClassRef = ReflectionUtils.GetTypeName(typeof(CustomEnumerable), FormatterAssemblyStyle.Simple, null); + string productClassRef = ReflectionUtils.GetTypeName(typeof(CustomEnumerable), TypeNameAssemblyFormatHandling.Simple, null); CustomEnumerable products = new CustomEnumerable(); @@ -1107,7 +1121,7 @@ namespace Newtonsoft.Json.Tests.Serialization string output = JsonConvert.SerializeObject(testerObject, Formatting.Indented, jsonSettings); - string carClassRef = ReflectionUtils.GetTypeName(typeof(Car), FormatterAssemblyStyle.Simple, null); + string carClassRef = ReflectionUtils.GetTypeName(typeof(Car), TypeNameAssemblyFormatHandling.Simple, null); StringAssert.AreEqual(output, @"{ ""$type"": """ + carClassRef + @""", @@ -1823,8 +1837,13 @@ namespace Newtonsoft.Json.Tests.Serialization string serialized = JsonConvert.SerializeObject(input, Newtonsoft.Json.Formatting.Indented, - new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, TypeNameAssemblyFormat = FormatterAssemblyStyle.Full } // TypeNameHandling.Auto will work - ); + new JsonSerializerSettings + { + TypeNameHandling = TypeNameHandling.All, +#pragma warning disable 618 + TypeNameAssemblyFormat = FormatterAssemblyStyle.Full // TypeNameHandling.Auto will work +#pragma warning restore 618 + }); var output = JsonConvert.DeserializeObject>>(serialized, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All } diff --git a/Src/Newtonsoft.Json.Tests/Utilities/ReflectionUtilsTests.cs b/Src/Newtonsoft.Json.Tests/Utilities/ReflectionUtilsTests.cs index 21b7979d..c219d165 100644 --- a/Src/Newtonsoft.Json.Tests/Utilities/ReflectionUtilsTests.cs +++ b/Src/Newtonsoft.Json.Tests/Utilities/ReflectionUtilsTests.cs @@ -50,16 +50,16 @@ namespace Newtonsoft.Json.Tests.Utilities { string typeName; - typeName = ReflectionUtils.GetTypeName(typeof(IList), FormatterAssemblyStyle.Simple, null); + typeName = ReflectionUtils.GetTypeName(typeof(IList), TypeNameAssemblyFormatHandling.Simple, null); Assert.AreEqual("System.Collections.Generic.IList`1[[System.Type, mscorlib]], mscorlib", typeName); - typeName = ReflectionUtils.GetTypeName(typeof(IDictionary, IList>), FormatterAssemblyStyle.Simple, null); + typeName = ReflectionUtils.GetTypeName(typeof(IDictionary, IList>), TypeNameAssemblyFormatHandling.Simple, null); Assert.AreEqual("System.Collections.Generic.IDictionary`2[[System.Collections.Generic.IList`1[[System.Type, mscorlib]], mscorlib],[System.Collections.Generic.IList`1[[System.Type, mscorlib]], mscorlib]], mscorlib", typeName); - typeName = ReflectionUtils.GetTypeName(typeof(IList<>), FormatterAssemblyStyle.Simple, null); + typeName = ReflectionUtils.GetTypeName(typeof(IList<>), TypeNameAssemblyFormatHandling.Simple, null); Assert.AreEqual("System.Collections.Generic.IList`1, mscorlib", typeName); - typeName = ReflectionUtils.GetTypeName(typeof(IDictionary<,>), FormatterAssemblyStyle.Simple, null); + typeName = ReflectionUtils.GetTypeName(typeof(IDictionary<,>), TypeNameAssemblyFormatHandling.Simple, null); Assert.AreEqual("System.Collections.Generic.IDictionary`2, mscorlib", typeName); } } diff --git a/Src/Newtonsoft.Json/JsonSerializer.cs b/Src/Newtonsoft.Json/JsonSerializer.cs index 75401162..a5aa7bcc 100644 --- a/Src/Newtonsoft.Json/JsonSerializer.cs +++ b/Src/Newtonsoft.Json/JsonSerializer.cs @@ -45,7 +45,7 @@ namespace Newtonsoft.Json public class JsonSerializer { internal TypeNameHandling _typeNameHandling; - internal FormatterAssemblyStyle _typeNameAssemblyFormat; + internal TypeNameAssemblyFormatHandling _typeNameAssemblyFormatHandling; internal PreserveReferencesHandling _preserveReferencesHandling; internal ReferenceLoopHandling _referenceLoopHandling; internal MissingMemberHandling _missingMemberHandling; @@ -161,9 +161,10 @@ namespace Newtonsoft.Json /// Gets or sets how a type name assembly is written and resolved by the serializer. /// /// The type name assembly format. + [Obsolete("TypeNameAssemblyFormat is obsolete. Use TypeNameAssemblyFormatHandling instead.")] public virtual FormatterAssemblyStyle TypeNameAssemblyFormat { - get { return _typeNameAssemblyFormat; } + get { return (FormatterAssemblyStyle)_typeNameAssemblyFormatHandling; } set { if (value < FormatterAssemblyStyle.Simple || value > FormatterAssemblyStyle.Full) @@ -171,7 +172,25 @@ namespace Newtonsoft.Json throw new ArgumentOutOfRangeException(nameof(value)); } - _typeNameAssemblyFormat = value; + _typeNameAssemblyFormatHandling = (TypeNameAssemblyFormatHandling)value; + } + } + + /// + /// Gets or sets how a type name assembly is written and resolved by the serializer. + /// + /// The type name assembly format. + public virtual TypeNameAssemblyFormatHandling TypeNameAssemblyFormatHandling + { + get { return _typeNameAssemblyFormatHandling; } + set + { + if (value < TypeNameAssemblyFormatHandling.Simple || value > TypeNameAssemblyFormatHandling.Full) + { + throw new ArgumentOutOfRangeException(nameof(value)); + } + + _typeNameAssemblyFormatHandling = value; } } @@ -594,9 +613,9 @@ namespace Newtonsoft.Json { serializer.MetadataPropertyHandling = settings.MetadataPropertyHandling; } - if (settings._typeNameAssemblyFormat != null) + if (settings._typeNameAssemblyFormatHandling != null) { - serializer.TypeNameAssemblyFormat = settings.TypeNameAssemblyFormat; + serializer.TypeNameAssemblyFormatHandling = settings.TypeNameAssemblyFormatHandling; } if (settings._preserveReferencesHandling != null) { diff --git a/Src/Newtonsoft.Json/JsonSerializerSettings.cs b/Src/Newtonsoft.Json/JsonSerializerSettings.cs index d3b9b49c..7a50e883 100644 --- a/Src/Newtonsoft.Json/JsonSerializerSettings.cs +++ b/Src/Newtonsoft.Json/JsonSerializerSettings.cs @@ -57,7 +57,7 @@ namespace Newtonsoft.Json internal const FloatParseHandling DefaultFloatParseHandling = FloatParseHandling.Double; internal const FloatFormatHandling DefaultFloatFormatHandling = FloatFormatHandling.String; internal const StringEscapeHandling DefaultStringEscapeHandling = StringEscapeHandling.Default; - internal const FormatterAssemblyStyle DefaultFormatterAssemblyStyle = FormatterAssemblyStyle.Simple; + internal const TypeNameAssemblyFormatHandling DefaultTypeNameAssemblyFormatHandling = Json.TypeNameAssemblyFormatHandling.Simple; internal static readonly CultureInfo DefaultCulture; internal const bool DefaultCheckAdditionalContent = false; internal const string DefaultDateFormatString = @"yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK"; @@ -75,7 +75,7 @@ namespace Newtonsoft.Json internal bool _maxDepthSet; internal string _dateFormatString; internal bool _dateFormatStringSet; - internal FormatterAssemblyStyle? _typeNameAssemblyFormat; + internal TypeNameAssemblyFormatHandling? _typeNameAssemblyFormatHandling; internal DefaultValueHandling? _defaultValueHandling; internal PreserveReferencesHandling? _preserveReferencesHandling; internal NullValueHandling? _nullValueHandling; @@ -182,10 +182,21 @@ namespace Newtonsoft.Json /// Gets or sets how a type name assembly is written and resolved by the serializer. /// /// The type name assembly format. + [Obsolete("TypeNameAssemblyFormat is obsolete. Use TypeNameAssemblyFormatHandling instead.")] public FormatterAssemblyStyle TypeNameAssemblyFormat { - get { return _typeNameAssemblyFormat ?? DefaultFormatterAssemblyStyle; } - set { _typeNameAssemblyFormat = value; } + get { return (FormatterAssemblyStyle)TypeNameAssemblyFormatHandling; } + set { TypeNameAssemblyFormatHandling = (TypeNameAssemblyFormatHandling)value; } + } + + /// + /// Gets or sets how a type name assembly is written and resolved by the serializer. + /// + /// The type name assembly format. + public TypeNameAssemblyFormatHandling TypeNameAssemblyFormatHandling + { + get { return _typeNameAssemblyFormatHandling ?? DefaultTypeNameAssemblyFormatHandling; } + set { _typeNameAssemblyFormatHandling = value; } } /// diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj index 45c90c96..1214a89c 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj @@ -144,6 +144,8 @@ + + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj index 064c86a1..63e1553b 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj @@ -158,6 +158,7 @@ + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net40.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net40.csproj index a80578fe..7ebbf8ca 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Net40.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net40.csproj @@ -113,6 +113,7 @@ + @@ -142,6 +143,7 @@ + @@ -156,6 +158,8 @@ + + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj index bf38c94e..c447f3b7 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj @@ -210,6 +210,7 @@ + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable40.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable40.csproj index 3013712c..0f96639f 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable40.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable40.csproj @@ -215,6 +215,7 @@ + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj index 31807f75..45e34059 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj @@ -212,6 +212,7 @@ + diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs index 6f2679e9..b5593f35 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs @@ -603,7 +603,7 @@ namespace Newtonsoft.Json.Serialization private void WriteTypeProperty(JsonWriter writer, Type type) { - string typeName = ReflectionUtils.GetTypeName(type, Serializer._typeNameAssemblyFormat, Serializer._binder); + string typeName = ReflectionUtils.GetTypeName(type, Serializer._typeNameAssemblyFormatHandling, Serializer._binder); if (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Verbose) { diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerProxy.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerProxy.cs index cd1c9101..8e46a8ee 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerProxy.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerProxy.cs @@ -121,12 +121,19 @@ namespace Newtonsoft.Json.Serialization set { _serializer.MetadataPropertyHandling = value; } } + [Obsolete("TypeNameAssemblyFormat is obsolete. Use TypeNameAssemblyFormatHandling instead.")] public override FormatterAssemblyStyle TypeNameAssemblyFormat { get { return _serializer.TypeNameAssemblyFormat; } set { _serializer.TypeNameAssemblyFormat = value; } } + public override TypeNameAssemblyFormatHandling TypeNameAssemblyFormatHandling + { + get { return _serializer.TypeNameAssemblyFormatHandling; } + set { _serializer.TypeNameAssemblyFormatHandling = value; } + } + public override ConstructorHandling ConstructorHandling { get { return _serializer.ConstructorHandling; } diff --git a/Src/Newtonsoft.Json/TypeNameAssemblyFormatHandling.cs b/Src/Newtonsoft.Json/TypeNameAssemblyFormatHandling.cs new file mode 100644 index 00000000..19324a88 --- /dev/null +++ b/Src/Newtonsoft.Json/TypeNameAssemblyFormatHandling.cs @@ -0,0 +1,43 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json +{ + /// + /// Indicates the method that will be used during deserialization for locating and loading assemblies. + /// + public enum TypeNameAssemblyFormatHandling + { + /// + /// In simple mode, the assembly used during deserialization need not match exactly the assembly used during serialization. Specifically, the version numbers need not match as the LoadWithPartialName method is used to load the assembly. + /// + Simple = 0, + + /// + /// In full mode, the assembly used during deserialization must match exactly the assembly used during serialization. The Load method of the Assembly class is used to load the assembly. + /// + Full = 1 + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs index a4b73df2..5fe2a605 100644 --- a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs @@ -151,7 +151,7 @@ namespace Newtonsoft.Json.Utilities return (v != null) ? v.GetType() : null; } - public static string GetTypeName(Type t, FormatterAssemblyStyle assemblyFormat, SerializationBinder binder) + public static string GetTypeName(Type t, TypeNameAssemblyFormatHandling assemblyFormat, SerializationBinder binder) { string fullyQualifiedTypeName; #if !(NET20 || NET35) @@ -171,9 +171,9 @@ namespace Newtonsoft.Json.Utilities switch (assemblyFormat) { - case FormatterAssemblyStyle.Simple: + case TypeNameAssemblyFormatHandling.Simple: return RemoveAssemblyDetails(fullyQualifiedTypeName); - case FormatterAssemblyStyle.Full: + case TypeNameAssemblyFormatHandling.Full: return fullyQualifiedTypeName; default: throw new ArgumentOutOfRangeException();