-
-
Save borakasmer/6fe0714cc78e4c99e541480f71ab25f0 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
using Core; | |
using CustomJsonConvertor; | |
using Microsoft.AspNetCore.Mvc; | |
using Newtonsoft.Json; | |
using System.Collections.Frozen; | |
using System.Net.WebSockets; | |
namespace DictionaryMap.Controllers | |
{ | |
[ApiController] | |
[Route("[controller]")] | |
public class CustomSerializeController : ControllerBase | |
{ | |
public CustomSerializeController(ILogger<WeatherForecastController> logger) | |
{ | |
} | |
[HttpGet("GetCustomSerialize")] | |
public string GetCustomSerialize() | |
{ | |
//List<Dictionary<string, object>> dictList = new(); | |
//Dictionary<string, object> dict = new Dictionary<string, object>(); | |
//var uniqueKey = $"bora@borakasmer.com{1}" + "|" + 2 + "|" + 653 + 1; | |
//dict.Add("uniqueKey", uniqueKey); | |
//dict.Add("Email", $"bora.kasmer@keepnetlabs.com{1}"); | |
//dict.Add("MailId", 653 + 1); | |
//dict.Add("MailType", MailType.SentItems); | |
//dict.Add("FolderName", $"Bora's Folder{1}"); | |
//dict.Add("From", $"Bora{1}"); | |
//dict.Add("Subject", $"Test Converter{1}"); | |
//dict.Add("SenderName", $"Bora{1}"); | |
//dict.Add("PostTime", DateTime.Now); | |
//dictList.Add(dict); | |
//Dictionary<string, string> columnMatchTable = new(){ | |
// { "Subject", "Konu" } | |
//}; | |
//var sentMail = dictList.DictionaryToList<SentMail>(columnMatchTable).First(); | |
SentMail mail = new() | |
{ | |
Email = "bora.kasmer78@gmail.com", | |
MailId = "653", | |
FolderName = "Bora's Folder", | |
From = "bora@borakasmer.com", | |
Konu = "Newtonsoft Injection", | |
SenderName = "Bora Kasmer", | |
PostTime = DateTime.Now | |
}; | |
Dictionary<string, string> replaceDic = new Dictionary<string, string> | |
{ | |
{ "bora", "Bill" }, | |
{ "kasmer", "Gates" } | |
}; | |
var dicReplacment = replaceDic.ToFrozenDictionary<string, string>(); | |
var result = JsonConvert.SerializeObject(mail, Formatting.Indented, new BoraJsonConvertor(dicReplacment, typeof(SentMail))); | |
return result; | |
//return JsonConvert.SerializeObject(sentMail, Formatting.Indented, new BoraJsonConvertor(typeof(SentMail))); | |
} | |
[HttpGet("GetCustomDeserialize")] | |
public SentMail GetCustomDeserialize() | |
{ | |
SentMail mail = new() | |
{ | |
Email = "bora.kasmer78@gmail.com", | |
MailId = "653", | |
FolderName = "Bora's Folder", | |
From = "bora@borakasmer.com", | |
Konu = "Newtonsoft Injection", | |
SenderName = "Bora Kasmer", | |
PostTime = DateTime.Now | |
}; | |
Dictionary<string, string> replaceDic = new Dictionary<string, string> | |
{ | |
{ "bora", "Bill" }, | |
{ "kasmer", "Gates" } | |
}; | |
var dicReplacment = replaceDic.ToFrozenDictionary<string, string>(); | |
var result = JsonConvert.SerializeObject(mail, Formatting.Indented, new BoraJsonConvertor(dicReplacment, typeof(SentMail))); | |
SentMail model = JsonConvert.DeserializeObject<SentMail>(result, new BoraJsonConvertor(dicReplacment, typeof(SentMail))); | |
return model; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment