Dynamic LINQ - Dynamic Class

CSharp · Console

/Program.cs

using System;
using System.Linq.Dynamic.Core;

var properties = new[]
{
    new DynamicProperty("Name", typeof(string)),
    new DynamicProperty("Birthday", typeof(DateTime))
};

Type type = DynamicClassFactory.CreateType(properties);

var instance = Activator.CreateInstance(type);
type.GetProperty("Name").SetValue(instance, "Mozart");
type.GetProperty("Birthday").SetValue(instance, new DateTime(1756, 1, 27));

Console.WriteLine(instance);

// Output:
// { Name = Mozart, Birthday = 01/27/1756 00:00:00 }
;