Skip to content

Instantly share code, notes, and snippets.

View lbargaoanu's full-sized avatar

Lucian Bargaoanu lbargaoanu

View GitHub Profile
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));
});
using ...
static void Main(string[] args)
{
var x = (Microsoft.Office.Interop.Excel._Application) Marshal.GetActiveObject("Excel.Application");
x.ChartDataPointTrack = false;
MapperRegistry.Mappers.Add(new ComObjectMapper());
var config = new MapperConfiguration(c => c.CreateMap<Microsoft.Office.Interop.Excel._Application, App>());
config.AssertConfigurationIsValid();
var mapper = config.CreateMapper();
using static Expression;
public static class Extensions
{
public static IMappingExpression<TSource, TDestination> Flatten<TSource, TDestination, TSourceMember>(
this IMappingExpression<TSource, TDestination> map,
Expression<Func<TSource, TSourceMember>> source)
{
var innerSourceProperties =
from sp in typeof(TSourceMember).GetProperties()
@lbargaoanu
lbargaoanu / AutoMapper.cs
Last active February 17, 2023 18:47
Sample AM
static void Main(string[] args)
{
var config = new MapperConfiguration(c =>
{
c.CreateMap<Model, Dto>();
c.CreateMap<Item, ItemDto>();
});
config.AssertConfigurationIsValid();
var configurationExpression = new MapperConfigurationExpression();
configurationExpression.RemoveUnusedFeatures();
configurationExpression.AddProfile<MyMappings>();
var config = new MapperConfiguration(configurationExpression);
class MyMappings : Profile
{
public MyMappings()
{
this.RemoveUnusedFeatures();
}
using System;
using System.Threading;
using System.Collections.Concurrent;
using System.Diagnostics;
namespace UiPath.CoreIpc.Tests
{
public class GuiLikeSyncContext : SynchronizationContext
{
private readonly BlockingCollection<(SendOrPostCallback Callback, object State)> _workQueue = new BlockingCollection<(SendOrPostCallback, object)>();
@lbargaoanu
lbargaoanu / ProjectToFlattening.cs
Last active November 25, 2018 10:38
ProjectToFlattening.cs
static void Main(string[] args)
{
Mapper.Initialize(cfg =>
{
cfg.AddProfile<MyMapperProfile>();
});
Mapper.AssertConfigurationIsValid();
new[]{new OrderDTO{ customer = new customer { ID = 1, name = "john" }}}.AsQueryable().ProjectTo<Order>().Dump();
}
public class Order
void Main()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMap<Source, Destination>().ForMember(dest => dest.ValuesCount, opt => opt.MapFrom(s=>s.Value1+s.Value2));
cfg.CreateMap<SourceItem, DestItem>();
});
Mapper.AssertConfigurationIsValid();
//Mapper.Configuration.BuildExecutionPlan(typeof(Source), typeof(Destination)).ToReadableString().Dump();
var expression = Mapper.Configuration.ResolveTypeMap(typeof(Source), typeof(Destination)).PropertyMaps.Last().CustomMapExpression;
public void Main()
{
var config = new MapperConfiguration(cfg => {
cfg.CreateMissingTypeMaps = false;
cfg.CreateMap<DateTimeDetails, PickupDetails>().ForMember(dest => dest.time, opt => opt.MapFrom(src => src));
cfg.CreateMap<DateTime?, DateString>().ConvertUsing(src => new DateString { Value = src.HasValue ? src.Value.ToString("yyyyMMdd") : String.Empty});
cfg.CreateMap<DateTimeDetails, TimeString>()
.ForMember(dest => dest.timeZoneOffset, opt => opt.MapFrom(src => src.TimeZoneOffset.ToString()))
.ForMember(dest => dest.Value, opt => opt.MapFrom(src => src.Time));
});
void Main()
{
Mapper.Initialize(cfg=>
{
cfg.CreateMap<object, bool>().ConvertUsing(o=>o!=null);
cfg.RecognizeDestinationPostfixes("Specified");
});
Mapper.AssertConfigurationIsValid();