Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Serialization;
  5.  
  6. namespace ConsoleApp1
  7. {
  8. class Program
  9. {
  10. public static void Main()
  11. {
  12. var cr = (IContractResolver) new CamelCasePropertyNamesContractResolver();
  13.  
  14. var t = new Test();
  15. t.Dict = new Dictionary<string, string>();
  16. t.Dict["RLLdfdFFf"] = "fsdfsFdfds";
  17.  
  18. Console.WriteLine(JsonConvert.SerializeObject(t, new JsonSerializerSettings()
  19. {
  20. ContractResolver = cr
  21. }));
  22.  
  23. Console.ReadLine();
  24. }
  25.  
  26. public class Test
  27. {
  28. [JsonProperty(NamingStrategyType = typeof(MyNamingStrategy))]
  29. public Dictionary<string, string> Dict { get; set; }
  30. }
  31.  
  32. public class MyNamingStrategy : NamingStrategy
  33. {
  34. public MyNamingStrategy() : base()
  35. {
  36. ProcessDictionaryKeys = false;
  37. OverrideSpecifiedNames = true;
  38. }
  39.  
  40. public override string GetDictionaryKey(string key)
  41. {
  42. return key;
  43. }
  44. protected override string ResolvePropertyName(string name)
  45. {
  46. return name;
  47. }
  48. }
  49.  
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement