Files
Newtonsoft.Json/Src/Newtonsoft.Json/Serialization/NamingStrategy.cs
T
stakx e19ac3f28c Add & fix crefs in XML document comments
* Add references to types where they are missing.

 * Fix incorrect references to closed generic types.

 * Convert member ID strings to proper references where they can be
   converted without breaking the build. The remaining member ID
   strings usually mean that the comment would have to be rephrased
   for at least one build target / platform.

 * Drop namespaces from type names where they are unnecessary.

 * Fix the odd typo and add additional <c> markup in a few places.
2016-12-23 16:15:24 +01:00

59 lines
2.1 KiB
C#

namespace Newtonsoft.Json.Serialization
{
/// <summary>
/// A base class for resolving how property names and dictionary keys are serialized.
/// </summary>
public abstract class NamingStrategy
{
/// <summary>
/// A flag indicating whether dictionary keys should be processed.
/// Defaults to <c>false</c>.
/// </summary>
public bool ProcessDictionaryKeys { get; set; }
/// <summary>
/// A flag indicating whether explicitly specified property names,
/// e.g. a property name customized with a <see cref="JsonPropertyAttribute"/>, should be processed.
/// Defaults to <c>false</c>.
/// </summary>
public bool OverrideSpecifiedNames { get; set; }
/// <summary>
/// Gets the serialized name for a given property name.
/// </summary>
/// <param name="name">The initial property name.</param>
/// <param name="hasSpecifiedName">A flag indicating whether the property has had a name explicitly specified.</param>
/// <returns>The serialized property name.</returns>
public virtual string GetPropertyName(string name, bool hasSpecifiedName)
{
if (hasSpecifiedName && !OverrideSpecifiedNames)
{
return name;
}
return ResolvePropertyName(name);
}
/// <summary>
/// Gets the serialized key for a given dictionary key.
/// </summary>
/// <param name="key">The initial dictionary key.</param>
/// <returns>The serialized dictionary key.</returns>
public virtual string GetDictionaryKey(string key)
{
if (!ProcessDictionaryKeys)
{
return key;
}
return ResolvePropertyName(key);
}
/// <summary>
/// Resolves the specified property name.
/// </summary>
/// <param name="name">The property name to resolve.</param>
/// <returns>The resolved property name.</returns>
protected abstract string ResolvePropertyName(string name);
}
}