Skip to content

Instantly share code, notes, and snippets.

View lbargaoanu's full-sized avatar

Lucian Bargaoanu lbargaoanu

View GitHub Profile
@lbargaoanu
lbargaoanu / gist:19e8ec659cb1d7e71df4
Created January 15, 2016 13:50
Mapping classes and interfaces
void Main()
{
Mapper.CreateMap<class1, iclass1DTO>().Include<class2, iclass2DTO>().Include<class3, iclass3DTO>().Include<class4, iclass4DTO>()
.ConstructUsing((ResolutionContext _)=>new class1DTO()).As<class1DTO>();
Mapper.CreateMap<class2, iclass2DTO>().As<class2DTO>();
Mapper.CreateMap<class3, iclass3DTO>().As<class3DTO>();
Mapper.CreateMap<class4, iclass4DTO>().As<class4DTO>();
try
{
@lbargaoanu
lbargaoanu / gist:454185b75ed017a8b81a
Created January 15, 2016 14:32
InterfacesAndClases 2.0
void Main()
{
Mapper.CreateMap<class1, iclass1DTO>().As<class1DTO>();
Mapper.CreateMap<class2, iclass2DTO>().IncludeBase<class1, class1DTO>().As<class2DTO>();
Mapper.CreateMap<class3, iclass3DTO>().IncludeBase<class2, class2DTO>().As<class3DTO>();
Mapper.CreateMap<class4, iclass4DTO>().IncludeBase<class3, class3DTO>().As<class4DTO>();
try
{
Mapper.Configuration.Seal();
void Main()
{
Mapper.CreateMap<iclass1, iclass1DTO>();
Mapper.CreateMap<iclass2, iclass2DTO>();
try
{
Mapper.AssertConfigurationIsValid();
var bo = new class2 { prop1 = "PROP1", prop2 = "PROP2" };
@lbargaoanu
lbargaoanu / project.json
Created February 5, 2016 10:52
AutoFixture project.json
{
"version": "3.38.1-*",
"description": "AutoFixture Class Library",
"authors": [ "" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"frameworks": {
"net451": {
"frameworkAssemblies": {
void Main()
{
var source = new PaginatedList<Source> { PageNumber = 13, PageSize = 5 };
source.AddRange(Enumerable.Range(1, 10).Reverse().Select(i=>new Source(i)));
var result = AutoMapperConfig.Mapper.Map<PaginatedList<Destination>>(source).Dump();
result.PageNumber.Dump();
result.PageSize.Dump();
}
@lbargaoanu
lbargaoanu / EF Self Referencing Model.cs
Created March 2, 2016 09:42
EF Self Referencing Model
using System;
using System.Linq;
using System.Data.Entity;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using System.Collections.Generic;
namespace SelfReferencingWithViewModel
{
@lbargaoanu
lbargaoanu / gist:8263a9f001107ac6ae1b
Created March 2, 2016 12:31
Child -> parent conversion issue
using System;
namespace AutoMapper_Sample
{
class Program
{
abstract class DTOParent
{
}
@lbargaoanu
lbargaoanu / FindInheritedInterfaceMember.cs
Last active March 14, 2016 10:41
Query inherited interfaces to find member #1182
void Main()
{
var interfaceType = typeof(IQueryableInterface);
new[]{interfaceType}
.RecursiveSelect(i=>i.GetTypeInfo().ImplementedInterfaces)
.Distinct()
.Select(i=>i.GetMember("PropertyInterface").FirstOrDefault())
.FirstOrDefault(m=>m!=null)
.Dump();
typeof(IQueryableInterface).GetMember("PropertyInterface").Dump();
void Main()
{
var config = new AutoMapper.MapperConfiguration(c =>
{
c.CreateMap<B, A>();
c.CreateMap<A, AB>();
c.CreateMap<B, AB>();
});
var mapper = config.CreateMapper();
var runtimeMapper = (IRuntimeMapper) mapper;
<Query Kind="Statements">
<Reference Relative="..\TestConsole\TestConsole\bin\Debug\Newtonsoft.Json.dll">C:\Projects\TestConsole\TestConsole\bin\Debug\Newtonsoft.Json.dll</Reference>
<Reference Relative="..\TestConsole\TestConsole\bin\Debug\TestConsole.exe">C:\Projects\TestConsole\TestConsole\bin\Debug\TestConsole.exe</Reference>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>OGL_Library</Namespace>
</Query>
var dir = Path.GetDirectoryName(LINQPad.Util.CurrentQueryPath);
var jsonText = File.ReadAllText(dir+"\\Saved Places.json");
dynamic json = JsonConvert.DeserializeObject(jsonText);