Tuesday, 11 July 2017

C#: How can I create a class dynamically from text?

The following code is a really simple way to create a class dynamically from string.

 dynamic data = new ExpandoObject();

IDictionary<string, object> dictionary = (IDictionary<string, object>)data;
dictionary.Add("FirstName", "Richard");
dictionary.Add("Surname", "Leeman");

Console.WriteLine(data.FirstName + " " + data.Surame);

No comments:

Post a comment