diff --git a/docs/Getting-started.rst b/docs/Getting-started.rst index de64025..20845f7 100644 --- a/docs/Getting-started.rst +++ b/docs/Getting-started.rst @@ -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 +`_ diff --git a/Threenine.Map/ICustomMap.cs b/src/ICustomMap.cs similarity index 100% rename from Threenine.Map/ICustomMap.cs rename to src/ICustomMap.cs diff --git a/Threenine.Map/IMapFrom.cs b/src/IMapFrom.cs similarity index 100% rename from Threenine.Map/IMapFrom.cs rename to src/IMapFrom.cs diff --git a/Threenine.Map/IMapTo.cs b/src/IMapTo.cs similarity index 100% rename from Threenine.Map/IMapTo.cs rename to src/IMapTo.cs diff --git a/Threenine.Map/MapConfigurationFactory.cs b/src/MapConfigurationFactory.cs similarity index 96% rename from Threenine.Map/MapConfigurationFactory.cs rename to src/MapConfigurationFactory.cs index bad2b4e..8b8ba40 100644 --- a/Threenine.Map/MapConfigurationFactory.cs +++ b/src/MapConfigurationFactory.cs @@ -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(Func 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 types) - { - Mapper.Initialize( - cfg => - { - LoadStandardMappings(cfg, types); - LoadCustomMappings(cfg, types); - }); - } - - - public static void LoadCustomMappings(IMapperConfigurationExpression config, IList 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 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(Func 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 types) + { + Mapper.Initialize( + cfg => + { + LoadStandardMappings(cfg, types); + LoadCustomMappings(cfg, types); + }); + } + + + public static void LoadCustomMappings(IMapperConfigurationExpression config, IList 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 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); + } + } + } } \ No newline at end of file diff --git a/Threenine.Map/Threenine.Map.csproj b/src/Threenine.Map.csproj similarity index 93% rename from Threenine.Map/Threenine.Map.csproj rename to src/Threenine.Map.csproj index e971d21..c987af3 100644 --- a/Threenine.Map/Threenine.Map.csproj +++ b/src/Threenine.Map.csproj @@ -20,6 +20,9 @@ - added new Scan Method + + + diff --git a/src/readme.txt b/src/readme.txt new file mode 100644 index 0000000..27a81cc --- /dev/null +++ b/src/readme.txt @@ -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 \ No newline at end of file