automapper-4

How to map an int to its enum description using AutoMapper during a queryable projection?

为君一笑 提交于 2019-11-30 16:15:16
问题 Here is the enum extension method to get its description attribute. public static string GetDescription(this Enum enumeration) { if (enumeration == null) throw new ArgumentNullException(); var value = enumeration.ToString(); var type = enumeration.GetType(); var descriptionAttribute = (DescriptionAttribute[]) type.GetField(value).GetCustomAttributes(typeof (DescriptionAttribute), false); return descriptionAttribute.Length > 0 ? descriptionAttribute[0].Description : value; } Here is the source

Mapping flat JSON/Dictionary to model (containing sub classes)

谁都会走 提交于 2019-11-30 16:04:18
问题 I want to turn a flat json string into a model, the destination class has subclasses, and the flat json has all of the sub class objects with prefix; like "{classname}.{property}". { "FirstName": "Joey", "LastName": "Billy", "EmploymentDetails.JobTitle": "JobTitle", "EmploymentDetails.StartDate": "2015-01-01T00:00:00", "ContactDetails.HouseNumberName": "10", "ContactDetails.Road": "Road" } This is my destination class: public class Person { public string FirstName { get; set; } public string

Mapping flat JSON/Dictionary to model (containing sub classes)

筅森魡賤 提交于 2019-11-30 15:42:45
I want to turn a flat json string into a model, the destination class has subclasses, and the flat json has all of the sub class objects with prefix; like "{classname}.{property}". { "FirstName": "Joey", "LastName": "Billy", "EmploymentDetails.JobTitle": "JobTitle", "EmploymentDetails.StartDate": "2015-01-01T00:00:00", "ContactDetails.HouseNumberName": "10", "ContactDetails.Road": "Road" } This is my destination class: public class Person { public string FirstName { get; set; } public string LastName { get; set; } public virtual EmploymentDetails EmploymentDetails { get;set;} public virtual

Using AutoMapper to merge objects

不想你离开。 提交于 2019-11-28 04:35:59
问题 I'm attempting to use AutoMapper to merge data from multiple objects, and I'm running into a couple issues that I can't seem to solve. I have an object like: public class Parent { public string Id { get; set; } public List<Child> Children { get; set; } } public class Child { public string Key { get; set; } public int? Value1 { get; set; } public int? Value2 { get; set; } public int? Value3 { get; set; } public int? Value4 { get; set; } public int? Value5 { get; set; } } Obviously the child