mirror of
https://github.com/bitwarden/server.git
synced 2024-12-02 13:53:23 +01:00
22 lines
631 B
C#
22 lines
631 B
C#
using Newtonsoft.Json.Serialization;
|
|
using System;
|
|
|
|
namespace Bit.Core.Utilities
|
|
{
|
|
public class EnumKeyResolver<T> : DefaultContractResolver where T : struct
|
|
{
|
|
protected override JsonDictionaryContract CreateDictionaryContract(Type objectType)
|
|
{
|
|
var contract = base.CreateDictionaryContract(objectType);
|
|
var keyType = contract.DictionaryKeyType;
|
|
|
|
if(keyType.BaseType == typeof(Enum))
|
|
{
|
|
contract.DictionaryKeyResolver = propName => ((T)Enum.Parse(keyType, propName)).ToString();
|
|
}
|
|
|
|
return contract;
|
|
}
|
|
}
|
|
}
|