This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
Mapper.Initialize(cfg => | |
{ | |
cfg.AllowNullDestinationValues = true; | |
cfg.AllowNullCollections = true; | |
cfg.SourceMemberNamingConvention = new LowerUnderscoreNamingConvention(); | |
cfg.DestinationMemberNamingConvention = new PascalCaseNamingConvention(); | |
cfg.RecognizeDestinationPrefixes("DTO_"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void Main(string[] args) | |
{ | |
Mapper.Initialize(x => { | |
x.CreateMap<To, From>() | |
.ReverseMap(); | |
x.CreateMap<string, Serialized>() | |
.ConvertUsing(y => JsonConvert.DeserializeObject<Serialized>(y)); | |
x.CreateMap<Serialized, string>() | |
.ConvertUsing(y => JsonConvert.SerializeObject(y)); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
Mapper.Initialize(cfg => | |
{ | |
cfg.CreateMap<Source, Destination>(); | |
cfg.CreateMap<Source, IDestination>().As<Destination>(); | |
}); | |
Mapper.AssertConfigurationIsValid(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
var config = new MapperConfiguration(cfg => | |
{ | |
cfg.CreateMap<A, ADto>().ForMember(_ => _.ListOfB, _ => _.UseDestinationValue()); | |
cfg.CreateMap<B, BDto>(); | |
cfg.CreateMap<B1, B1Dto>().IncludeBase<B, BDto>(); | |
}); | |
config.AssertConfigurationIsValid(); | |
var mapper = config.CreateMapper(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ProtoBuf; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace TestConsole | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Main() | |
{ | |
Mapper.Initialize(cfg => | |
{ | |
cfg.CreateMap<ExpandoObject, Destination>().ConvertUsing((expando, destination, context)=> | |
{ | |
var dictionary = context.Mapper.Map<Dictionary<string,object>>(expando); | |
context.Mapper.Map(dictionary, destination); | |
// after map | |
return destination; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main() | |
{ | |
Mapper.Initialize(cfg => | |
{ | |
//cfg.AllowNullDestinationValues.Dump(); | |
cfg.CreateMap<TimesheetModel, TimesheetViewModel>() | |
.ForMember(d=>d.Contact, o=>o.MapFrom(s=>s.ContactNavigation.Id)) | |
.ReverseMap(); | |
}); | |
Mapper.AssertConfigurationIsValid(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
var config = new MapperConfiguration(c => | |
{ | |
c.CreateMap<Model, Dto>(); | |
c.CreateMap<Item, ItemDto>(); | |
}); | |
config.AssertConfigurationIsValid(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Main() | |
{ | |
var config = new MapperConfiguration(cfg => | |
{ | |
cfg.CreateProjection<Product, ProductArticle>() | |
.ForMember(d => d.Price, o => o.MapFrom(source => source.Articles.Where(x => x.IsDefault && x.NationId == 1 && source.ECommercePublished).FirstOrDefault())); | |
cfg.CreateProjection<ProductArticle, ProductModel>(); | |
cfg.CreateProjection<Article, PriceModel>() | |
.ForMember(d => d.RegionId, o => o.MapFrom(s => s.NationId)); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Xml; | |
using System.Reflection; | |
using System.Diagnostics; | |
using System.Globalization; | |
using System.ComponentModel; | |
using System.Collections.Generic; | |
public static class ConfigurationManager |