Created
July 4, 2018 04:44
-
-
Save bhavjot/40d642ffabf9e0cc964d49cb75df5977 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomContractResolver : DefaultContractResolver | |
{ | |
private Dictionary<string, string[]> PropertyMappings { get; set; } | |
public CustomContractResolver() | |
{ | |
this.PropertyMappings = new Dictionary<string, string[]> | |
{ | |
{"Values", new string[]{"AU", "EU" } } | |
}; | |
} | |
//protected override string ResolvePropertyName(string propertyName) | |
//{ | |
// string[] resolvedName = null; | |
// var resolved = this.PropertyMappings.TryGetValue(propertyName, out resolvedName); | |
// return (resolved) ? resolvedName : base.ResolvePropertyName(propertyName); | |
//} | |
private Dictionary<Type, Dictionary<string, string>> memberNameToJsonNameMap; | |
//public DynamicMappingResolver(Dictionary<Type, Dictionary<string, string>> memberNameToJsonNameMap) | |
//{ | |
// this.memberNameToJsonNameMap = memberNameToJsonNameMap; | |
//} | |
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) | |
{ | |
if(member.GetType() == typeof(double?[]) && member.Name == "Values") | |
{ | |
string[] resolvedName = null; | |
var resolved = this.PropertyMappings.TryGetValue(member.Name, out resolvedName); | |
foreach (var item in resolvedName) | |
{ | |
// JsonProperty prop = base.CreateProperty(; | |
} | |
} | |
JsonProperty prop = base.CreateProperty(member, memberSerialization); | |
Dictionary<string, string> dict; | |
string jsonName; | |
if (memberNameToJsonNameMap.TryGetValue(member.DeclaringType, out dict) && | |
dict.TryGetValue(member.Name, out jsonName)) | |
{ | |
prop.PropertyName = jsonName; | |
} | |
return prop; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment