-Added TypeNameAssemblyFormatHandling

-Added TypeNameAssemblyFormatHandling properties to JsonSerializer and JsonSerializerSettings
-Changed TypeNameAssemblyFormat properties on JsonSerializer and JsonSerializerSettings to obsolete
This commit is contained in:
James Newton-King
2016-09-17 15:57:03 +12:00
parent a0403492ad
commit ca27a0fc3a
17 changed files with 184 additions and 33 deletions
@@ -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);
@@ -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);
}
@@ -376,7 +376,9 @@ namespace Newtonsoft.Json.Tests.Serialization
List<object> values = (List<object>)JsonConvert.DeserializeObject(json, typeof(List<object>), 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<int>), FormatterAssemblyStyle.Simple, null);
string listRef = ReflectionUtils.GetTypeName(typeof(List<int>), TypeNameAssemblyFormatHandling.Simple, null);
TypeNameHandlingTests.TypeNameProperty typeNameProperty = new TypeNameHandlingTests.TypeNameProperty
{
@@ -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<object> values = (List<object>)JsonConvert.DeserializeObject(json, typeof(List<object>), 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<ICorrelatedMessage>(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<int>), FormatterAssemblyStyle.Simple, null);
string listRef = ReflectionUtils.GetTypeName(typeof(List<int>), 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<int, IList<ContentBaseClass>>), FormatterAssemblyStyle.Simple, null);
string listRef = ReflectionUtils.GetTypeName(typeof(List<ContentBaseClass>), FormatterAssemblyStyle.Simple, null);
string contentSubClassRef = ReflectionUtils.GetTypeName(typeof(ContentSubClass), TypeNameAssemblyFormatHandling.Simple, null);
string dictionaryRef = ReflectionUtils.GetTypeName(typeof(Dictionary<int, IList<ContentBaseClass>>), TypeNameAssemblyFormatHandling.Simple, null);
string listRef = ReflectionUtils.GetTypeName(typeof(List<ContentBaseClass>), 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<string, object>), c);
@@ -1019,7 +1033,7 @@ namespace Newtonsoft.Json.Tests.Serialization
[Test]
public void SerializingIEnumerableOfTShouldRetainGenericTypeInfo()
{
string productClassRef = ReflectionUtils.GetTypeName(typeof(CustomEnumerable<Product>), FormatterAssemblyStyle.Simple, null);
string productClassRef = ReflectionUtils.GetTypeName(typeof(CustomEnumerable<Product>), TypeNameAssemblyFormatHandling.Simple, null);
CustomEnumerable<Product> products = new CustomEnumerable<Product>();
@@ -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<List<Stack<string>>>(serialized,
new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }
@@ -50,16 +50,16 @@ namespace Newtonsoft.Json.Tests.Utilities
{
string typeName;
typeName = ReflectionUtils.GetTypeName(typeof(IList<Type>), FormatterAssemblyStyle.Simple, null);
typeName = ReflectionUtils.GetTypeName(typeof(IList<Type>), TypeNameAssemblyFormatHandling.Simple, null);
Assert.AreEqual("System.Collections.Generic.IList`1[[System.Type, mscorlib]], mscorlib", typeName);
typeName = ReflectionUtils.GetTypeName(typeof(IDictionary<IList<Type>, IList<Type>>), FormatterAssemblyStyle.Simple, null);
typeName = ReflectionUtils.GetTypeName(typeof(IDictionary<IList<Type>, IList<Type>>), 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);
}
}
+24 -5
View File
@@ -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.
/// </summary>
/// <value>The type name assembly format.</value>
[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;
}
}
/// <summary>
/// Gets or sets how a type name assembly is written and resolved by the serializer.
/// </summary>
/// <value>The type name assembly format.</value>
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)
{
+15 -4
View File
@@ -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.
/// </summary>
/// <value>The type name assembly format.</value>
[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; }
}
/// <summary>
/// Gets or sets how a type name assembly is written and resolved by the serializer.
/// </summary>
/// <value>The type name assembly format.</value>
public TypeNameAssemblyFormatHandling TypeNameAssemblyFormatHandling
{
get { return _typeNameAssemblyFormatHandling ?? DefaultTypeNameAssemblyFormatHandling; }
set { _typeNameAssemblyFormatHandling = value; }
}
/// <summary>
@@ -144,6 +144,8 @@
<Compile Include="Serialization\TraceJsonReader.cs" />
<Compile Include="Serialization\TraceJsonWriter.cs" />
<Compile Include="StringEscapeHandling.cs" />
<Compile Include="TraceLevel.cs" />
<Compile Include="TypeNameAssemblyFormatHandling.cs" />
<Compile Include="Utilities\DateTimeParser.cs" />
<Compile Include="Utilities\DynamicProxy.cs" />
<Compile Include="Utilities\DynamicProxyMetaObject.cs" />
@@ -158,6 +158,7 @@
<Compile Include="Serialization\TraceJsonWriter.cs" />
<Compile Include="StringEscapeHandling.cs" />
<Compile Include="TraceLevel.cs" />
<Compile Include="TypeNameAssemblyFormatHandling.cs" />
<Compile Include="Utilities\DateTimeParser.cs" />
<Compile Include="Utilities\DynamicProxy.cs" />
<Compile Include="Linq\JRaw.cs" />
@@ -113,6 +113,7 @@
<Compile Include="Converters\VersionConverter.cs" />
<Compile Include="FloatFormatHandling.cs" />
<Compile Include="FloatParseHandling.cs" />
<Compile Include="FormatterAssemblyStyle.cs" />
<Compile Include="IArrayPool.cs" />
<Compile Include="JsonDictionaryAttribute.cs" />
<Compile Include="JsonException.cs" />
@@ -142,6 +143,7 @@
<Compile Include="Linq\MergeArrayHandling.cs" />
<Compile Include="Linq\MergeNullValueHandling.cs" />
<Compile Include="MetadataPropertyHandling.cs" />
<Compile Include="SerializationBinder.cs" />
<Compile Include="Serialization\CamelCaseNamingStrategy.cs" />
<Compile Include="Serialization\DefaultNamingStrategy.cs" />
<Compile Include="Serialization\DiagnosticsTraceWriter.cs" />
@@ -156,6 +158,8 @@
<Compile Include="Serialization\TraceJsonReader.cs" />
<Compile Include="Serialization\TraceJsonWriter.cs" />
<Compile Include="StringEscapeHandling.cs" />
<Compile Include="TraceLevel.cs" />
<Compile Include="TypeNameAssemblyFormatHandling.cs" />
<Compile Include="Utilities\DateTimeParser.cs" />
<Compile Include="Utilities\DynamicProxy.cs" />
<Compile Include="Linq\JRaw.cs" />
@@ -210,6 +210,7 @@
<Compile Include="Serialization\TraceJsonWriter.cs" />
<Compile Include="StringEscapeHandling.cs" />
<Compile Include="TraceLevel.cs" />
<Compile Include="TypeNameAssemblyFormatHandling.cs" />
<Compile Include="TypeNameHandling.cs" />
<Compile Include="Utilities\Base64Encoder.cs" />
<Compile Include="Utilities\BidirectionalDictionary.cs" />
@@ -215,6 +215,7 @@
<Compile Include="Serialization\TraceJsonWriter.cs" />
<Compile Include="StringEscapeHandling.cs" />
<Compile Include="TraceLevel.cs" />
<Compile Include="TypeNameAssemblyFormatHandling.cs" />
<Compile Include="TypeNameHandling.cs" />
<Compile Include="Utilities\Base64Encoder.cs" />
<Compile Include="Utilities\BidirectionalDictionary.cs" />
@@ -212,6 +212,7 @@
<Compile Include="Serialization\ReflectionValueProvider.cs" />
<Compile Include="Serialization\TraceJsonReader.cs" />
<Compile Include="Serialization\TraceJsonWriter.cs" />
<Compile Include="TypeNameAssemblyFormatHandling.cs" />
<Compile Include="StringEscapeHandling.cs" />
<Compile Include="TraceLevel.cs" />
<Compile Include="TypeNameHandling.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)
{
@@ -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; }
@@ -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
{
/// <summary>
/// Indicates the method that will be used during deserialization for locating and loading assemblies.
/// </summary>
public enum TypeNameAssemblyFormatHandling
{
/// <summary>
/// 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.
/// </summary>
Simple = 0,
/// <summary>
/// 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.
/// </summary>
Full = 1
}
}
@@ -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();