-Added DefaultContractResolver.ResolveDictionaryKey
-Added JsonDictionaryContract.DictionaryKeyResolver -Marked JsonDictionaryContract.PropertyNameResolver as obsolete
This commit is contained in:
@@ -92,5 +92,5 @@ using System.Security;
|
||||
// by using the '*' as shown below:
|
||||
|
||||
[assembly: AssemblyVersion("7.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("7.0.1.18502")]
|
||||
[assembly: AssemblyFileVersion("7.0.1.18503")]
|
||||
[assembly: CLSCompliant(true)]
|
||||
|
||||
@@ -880,7 +880,7 @@ namespace Newtonsoft.Json.Serialization
|
||||
JsonDictionaryContract contract = new JsonDictionaryContract(objectType);
|
||||
InitializeContract(contract);
|
||||
|
||||
contract.PropertyNameResolver = ResolvePropertyName;
|
||||
contract.DictionaryKeyResolver = ResolveDictionaryKey;
|
||||
|
||||
return contract;
|
||||
}
|
||||
@@ -1360,12 +1360,22 @@ namespace Newtonsoft.Json.Serialization
|
||||
/// Resolves the name of the property.
|
||||
/// </summary>
|
||||
/// <param name="propertyName">Name of the property.</param>
|
||||
/// <returns>Name of the property.</returns>
|
||||
/// <returns>Resolved name of the property.</returns>
|
||||
protected internal virtual string ResolvePropertyName(string propertyName)
|
||||
{
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the key of the dictionary. By default <see cref="M:ResolvePropertyName"/> is used to resolve dictionary keys.
|
||||
/// </summary>
|
||||
/// <param name="dictionaryKey">Key of the dictionary.</param>
|
||||
/// <returns>Resolved key of the dictionary.</returns>
|
||||
protected internal virtual string ResolveDictionaryKey(string dictionaryKey)
|
||||
{
|
||||
return ResolvePropertyName(dictionaryKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the resolved name of the property.
|
||||
/// </summary>
|
||||
|
||||
@@ -45,7 +45,18 @@ namespace Newtonsoft.Json.Serialization
|
||||
/// Gets or sets the property name resolver.
|
||||
/// </summary>
|
||||
/// <value>The property name resolver.</value>
|
||||
public Func<string, string> PropertyNameResolver { get; set; }
|
||||
[Obsolete("PropertyNameResolver is obsolete. Use DictionaryKeyResolver instead.")]
|
||||
public Func<string, string> PropertyNameResolver
|
||||
{
|
||||
get { return DictionaryKeyResolver; }
|
||||
set { DictionaryKeyResolver = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the dictionary key resolver.
|
||||
/// </summary>
|
||||
/// <value>The dictionary key resolver.</value>
|
||||
public Func<string, string> DictionaryKeyResolver { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Type"/> of the dictionary keys.
|
||||
|
||||
@@ -921,8 +921,8 @@ namespace Newtonsoft.Json.Serialization
|
||||
bool escape;
|
||||
string propertyName = GetPropertyName(writer, entry.Key, contract.KeyContract, out escape);
|
||||
|
||||
propertyName = (contract.PropertyNameResolver != null)
|
||||
? contract.PropertyNameResolver(propertyName)
|
||||
propertyName = (contract.DictionaryKeyResolver != null)
|
||||
? contract.DictionaryKeyResolver(propertyName)
|
||||
: propertyName;
|
||||
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user