NamingStrategy
A base class for resolving how property names and dictionary keys are serialized.
using System.Runtime.CompilerServices;
namespace Newtonsoft.Json.Serialization
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public abstract class NamingStrategy
{
public bool ProcessDictionaryKeys { get; set; }
public bool ProcessExtensionDataNames { get; set; }
public bool OverrideSpecifiedNames { get; set; }
public virtual string GetPropertyName(string name, bool hasSpecifiedName)
{
if (hasSpecifiedName && !OverrideSpecifiedNames)
return name;
return ResolvePropertyName(name);
}
public virtual string GetExtensionDataName(string name)
{
if (!ProcessExtensionDataNames)
return name;
return ResolvePropertyName(name);
}
public virtual string GetDictionaryKey(string key)
{
if (!ProcessDictionaryKeys)
return key;
return ResolvePropertyName(key);
}
protected abstract string ResolvePropertyName(string name);
public override int GetHashCode()
{
int num = GetType().GetHashCode() * 397;
bool flag = ProcessDictionaryKeys;
int num2 = (num ^ flag.GetHashCode()) * 397;
flag = ProcessExtensionDataNames;
int num3 = (num2 ^ flag.GetHashCode()) * 397;
flag = OverrideSpecifiedNames;
return num3 ^ flag.GetHashCode();
}
public override bool Equals(object obj)
{
return Equals(obj as NamingStrategy);
}
[System.Runtime.CompilerServices.NullableContext(2)]
protected bool Equals(NamingStrategy other)
{
if (other == null)
return false;
if ((object)GetType() == other.GetType() && ProcessDictionaryKeys == other.ProcessDictionaryKeys && ProcessExtensionDataNames == other.ProcessExtensionDataNames)
return OverrideSpecifiedNames == other.OverrideSpecifiedNames;
return false;
}
}
}