using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
var person = new Person() { Id = 1, Name = "Lập Trình VB.NET" };
dynamic eo = CopyWithOjbectModel(person);
var b = new List<Person>();
b.Add(new Person() { Id = 4, Name = "a" });
b.Add(new Person() { Id = 5, Name = "b" });
b.Add(new Person() { Id = 6, Name = "c" });
eo.Status = 1;
eo.Name = "Nguyễn Thảo";
eo.TrangThai = "Đẹp trai";
eo.Id = 2;
eo.Result = b;
var data = JsonConvert.SerializeObject(eo);
Console.ReadLine();
}
public static dynamic CopyWithOjbectModel<T>(T modelCopyWith)
{
string json = JsonConvert.SerializeObject(modelCopyWith);
dynamic dynamicObject = JsonConvert.DeserializeObject<ExpandoObject>(json);
return dynamicObject;
}
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Telephone { get; set; }
}
}
}