Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Serialization;
- namespace ConsoleApp1
- {
- class Program
- {
- public static void Main()
- {
- var cr = (IContractResolver) new CamelCasePropertyNamesContractResolver();
- var t = new Test();
- t.Dict = new Dictionary<string, string>();
- t.Dict["RLLdfdFFf"] = "fsdfsFdfds";
- Console.WriteLine(JsonConvert.SerializeObject(t, new JsonSerializerSettings()
- {
- ContractResolver = cr
- }));
- Console.ReadLine();
- }
- public class Test
- {
- [JsonProperty(NamingStrategyType = typeof(MyNamingStrategy))]
- public Dictionary<string, string> Dict { get; set; }
- }
- public class MyNamingStrategy : NamingStrategy
- {
- public MyNamingStrategy() : base()
- {
- ProcessDictionaryKeys = false;
- OverrideSpecifiedNames = true;
- }
- public override string GetDictionaryKey(string key)
- {
- return key;
- }
- protected override string ResolvePropertyName(string name)
- {
- return name;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement