Fix memory leak when (de)serializing objects with enums (#1991) (#1992)

This commit is contained in:
Mantas Audickas
2019-03-10 14:37:53 -07:00
committed by James Newton-King
parent 57a3a65464
commit d75d54381e
2 changed files with 170 additions and 0 deletions
@@ -101,5 +101,44 @@ namespace Newtonsoft.Json.Serialization
/// <param name="name">The property name to resolve.</param>
/// <returns>The resolved property name.</returns>
protected abstract string ResolvePropertyName(string name);
/// <summary>
/// Hash code calculation
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
unchecked
{
var hashCode = GetType().GetHashCode(); // make sure different types do not result in equal values
hashCode = (hashCode * 397) ^ ProcessDictionaryKeys.GetHashCode();
hashCode = (hashCode * 397) ^ ProcessExtensionDataNames.GetHashCode();
hashCode = (hashCode * 397) ^ OverrideSpecifiedNames.GetHashCode();
return hashCode;
}
}
/// <summary>
/// Object equality implementation
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj) => Equals(obj as NamingStrategy);
/// <summary>
/// Compare to another NamingStrategy
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
protected bool Equals(NamingStrategy other)
{
if (other == null)
return false;
return GetType() == other.GetType() &&
ProcessDictionaryKeys == other.ProcessDictionaryKeys &&
ProcessExtensionDataNames == other.ProcessExtensionDataNames &&
OverrideSpecifiedNames == other.OverrideSpecifiedNames;
}
}
}