Skip to content

Commit

Permalink
added readme
Browse files Browse the repository at this point in the history
  • Loading branch information
garywoodfine committed Feb 28, 2018
1 parent 574decf commit 19905bf
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 98 deletions.
4 changes: 4 additions & 0 deletions docs/Getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ Or dotnet core cli :

dotnet add package Threenine.Map

Source code
***********

All source code for this library is available for inspection at the `Threenine.map Github
<https://github.com/threenine/Threenine.Map/>`_
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,99 +1,99 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using AutoMapper;

namespace Threenine.Map
{
public class MapConfigurationFactory
{
public static void Scan<TType>(Func<AssemblyName, bool> assemblyFilter = null)
{
var target = typeof(TType).Assembly;

bool LoadAllFilter(AssemblyName x) => true;

var assembliesToLoad = target.GetReferencedAssemblies()
.Where(assemblyFilter ?? LoadAllFilter)
.Select(Assembly.Load)
.ToList();

assembliesToLoad.Add(target);

LoadMapsFromAssemblies(assembliesToLoad.ToArray());
}

public static void LoadMapsFromAssemblies(params Assembly[] assemblies)
{
var types = assemblies.SelectMany(a => a.GetExportedTypes()).ToArray();
LoadAllMappings(types);
}


public static void LoadAllMappings(IList<Type> types)
{
Mapper.Initialize(
cfg =>
{
LoadStandardMappings(cfg, types);
LoadCustomMappings(cfg, types);
});
}


public static void LoadCustomMappings(IMapperConfigurationExpression config, IList<Type> types)
{
var instancesToMap = (from t in types
from i in t.GetInterfaces()
where typeof(ICustomMap).IsAssignableFrom(t) &&
!t.IsAbstract &&
!t.IsInterface
select (ICustomMap) Activator.CreateInstance(t)).ToArray();


foreach (var map in instancesToMap)
{
map.CustomMap(config);
}
}

public static void LoadStandardMappings(IMapperConfigurationExpression config, IList<Type> types)
{
var mapsFrom = (from t in types
from i in t.GetInterfaces()
where i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMapFrom<>) &&
!t.IsAbstract &&
!t.IsInterface
select new
{
Source = i.GetGenericArguments()[0],
Destination = t
}).ToArray();


foreach (var map in mapsFrom)
{
config.CreateMap(map.Source, map.Destination);
}


var mapsTo = (from t in types
from i in t.GetInterfaces()
where i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMapTo<>) &&
!t.IsAbstract &&
!t.IsInterface
select new
{
Source = i.GetGenericArguments()[0],
Destination = t
}).ToArray();


foreach (var map in mapsTo)
{
config.CreateMap(map.Source, map.Destination);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using AutoMapper;

namespace Threenine.Map
{
public class MapConfigurationFactory
{
public static void Scan<TType>(Func<AssemblyName, bool> assemblyFilter = null)
{
var target = typeof(TType).Assembly;

bool LoadAllFilter(AssemblyName x) => true;

var assembliesToLoad = target.GetReferencedAssemblies()
.Where(assemblyFilter ?? LoadAllFilter)
.Select(Assembly.Load)
.ToList();

assembliesToLoad.Add(target);

LoadMapsFromAssemblies(assembliesToLoad.ToArray());
}

public static void LoadMapsFromAssemblies(params Assembly[] assemblies)
{
var types = assemblies.SelectMany(a => a.GetExportedTypes()).ToArray();
LoadAllMappings(types);
}


public static void LoadAllMappings(IList<Type> types)
{
Mapper.Initialize(
cfg =>
{
LoadStandardMappings(cfg, types);
LoadCustomMappings(cfg, types);
});
}


public static void LoadCustomMappings(IMapperConfigurationExpression config, IList<Type> types)
{
var instancesToMap = (from t in types
from i in t.GetInterfaces()
where typeof(ICustomMap).IsAssignableFrom(t) &&
!t.IsAbstract &&
!t.IsInterface
select (ICustomMap) Activator.CreateInstance(t)).ToArray();


foreach (var map in instancesToMap)
{
map.CustomMap(config);
}
}

public static void LoadStandardMappings(IMapperConfigurationExpression config, IList<Type> types)
{
var mapsFrom = (from t in types
from i in t.GetInterfaces()
where i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMapFrom<>) &&
!t.IsAbstract &&
!t.IsInterface
select new
{
Source = i.GetGenericArguments()[0],
Destination = t
}).ToArray();


foreach (var map in mapsFrom)
{
config.CreateMap(map.Source, map.Destination);
}


var mapsTo = (from t in types
from i in t.GetInterfaces()
where i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMapTo<>) &&
!t.IsAbstract &&
!t.IsInterface
select new
{
Source = i.GetGenericArguments()[0],
Destination = t
}).ToArray();


foreach (var map in mapsTo)
{
config.CreateMap(map.Source, map.Destination);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
- added new Scan Method</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
<None Include="readme.txt" Pack="True" PackagePath=".">
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="6.2.2" />
<PackageReference Include="System.Collections" Version="4.3.0" />
Expand Down
27 changes: 27 additions & 0 deletions src/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
======================================================================================
threenine.co.uk - Threenine.Map
======================================================================================

Thank you for downloading our package!

For more details regarding the package check out the package website https://threenine.github.io/Threenine.Map/

Documentation
=============

To help you to make the most use of the package we have detailed documentation available on Read The Docs
check out http://threeninemap.readthedocs.io/en/latest/Getting-started.html


Bugs & Feature Requests
=======================

If you experience any issues or would like some addtional functionality please raise an issue on Github
https://github.com/threenine/Threenine.Map/issues


Source Code
===========

All source code for the project is available on Github
https://github.com/threenine/Threenine.Map/tree/master/Threenine.Map

0 comments on commit 19905bf

Please sign in to comment.