Skip to content

Instantly share code, notes, and snippets.

@borakasmer
Created December 22, 2023 16:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save borakasmer/6fe0714cc78e4c99e541480f71ab25f0 to your computer and use it in GitHub Desktop.
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