1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 07:36:14 -05:00

refactor code to with user TwoFactorProviders

This commit is contained in:
Kyle Spearrin
2017-06-07 14:14:34 -04:00
parent d8c0994ed3
commit ecc2468409
10 changed files with 166 additions and 53 deletions

View File

@ -0,0 +1,21 @@
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;
}
}
}