Follow up from this question.
I would like to cast from Strongly Typed
to Anonymous Type
Result. For an example the following class should be converted to Anonymous Type Object during run time. Am struggling to achieve this.
public sealed class CountryModel
{
public int CountryId { get; set; }
public string CountryName { get; set; }
public string CountryCode { get; set; }
public bool IsActive { get; set; }
}
Usage:
new CountryModel()
{
CountryCode = "AOE",
CountryId = 2,
CountryName = "Anywhere on Earth",
IsActive = true
};
Anonymous type:
The above Strongly typed should be converted to Anonymous and the end result would look like this (captured via Immediate Window):
{ CountryId = 2, CountryName = "Anywhere on Earth", CountryCode = "AOE", IsActive = true }
CountryCode: "AOE"
CountryId: 2
CountryName: "Anywhere on Earth"
IsActive: true
Note: I need this casting to be done so that I can pass the object to Dapper.SimpleCRUD and Dapper ORM Library.
Try this:
var obj = new {
CountryCode = item.CountryCode,
CountryId = item.CountryId,
CountryName = item.CountryName,
IsActive = item.IsActive
};