!!!! Don't Use This Project !!!!

Use simple IMapper<In, Out> with dependecy injection instead !

I think the design of this mapping framework is today a bad practice and opposed to DI principles.

This solution was used in big scale projects and sucessfully used, but it's not something I would recommend nowadays. 

!!!! Don't Use This Project !!!!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Project Description

The purpose of this project is to provide a simple framework component to easily map object from different types. A simple example is given just below. For now the project is still in pre beta version, unit tests are not yet published and documentation is not published too. But this little piece of code is really easy to use and really easy to understand.


Materials

Introduction Video : Coming soon.
Prezi presentation : http://prezi.com/unensqkwjkcc/mf-mapping-framework-a-brief-introduction/?kw=view-unensqkwjkcc&rc=ref-25841641

 


 

Example  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Istace.Framework.Mapping.Core;
using Istace.Framework.Mapping.Core.Interfaces;

namespace Istace.Framework.Mapping.TestConsole
{
    static class Program
    {
        static void Main()
        {
            // Initialize the mappers with the given assemblies in the app.config
            // They will be inspected and their dependencies too. (configurable)
            Mapper.Initialize(typeof(Program).Assembly, true, true);

            // Add object to a string repository
            Repository.AddInstance("string", "string", true);
            Repository.AddInstance("string2", "string2", true);
            Repository.AddInstance("string", "string3", true);

            // Add object to an integer repository
            Repository.AddInstance("string", 20);
            Repository.AddInstance("test", 10);
            
            // Display the indexed value from a repository
            Console.WriteLine("Display the string referenced with 'string' index : {0}",    Repository.GetInstance<string>("string"));
            Console.WriteLine("Display integer referenced with 'string' index : {0}",       Repository.GetInstance<int>("string"));
            Console.WriteLine("Display integer referenced with 'test' index : {0}",         Repository.GetInstance<int>("test"));

            // Test some basic mapping features
            Console.WriteLine("\nCall Map<int, string> method : {0}",   Mapper.Map<int, string>(10));
            Console.WriteLine("Call Map<string, int> method : {0}",     Mapper.Map<string, int>("456"));
            Console.WriteLine("Call Map<int> method : {0}",             Mapper.Map<int>("456"));
            Console.WriteLine("Call Map<A, string> method : {0}",       Mapper.Map<A, string>(new A { Foo = "Foo text" }));

            // A little demo with list
            Console.WriteLine("\nConvert a list of string to integer with MapList<string, int> \n{0}",  String.Join(Environment.NewLine, Mapper.MapList<int>(new List<string> { "0", "1", "2", "3" }).ToList()));
            Console.WriteLine("\nConvert a list of A to string with MapList<string> \n{0}",             String.Join(Environment.NewLine, Mapper.MapList<string>(new List<A> { new A { Foo = "First" }, new A { Foo = "Second" } })));

            Console.ReadKey();           
        }
    }

    /// <summary>
    /// Convert integer to string
    /// </summary>
    public class IntegerToStringMapper : IMapper<int, string>, IMapper<string, int>
    {
        public string Map(int instanceToMap)
        {
            return instanceToMap.ToString();
        }

        public int Map(string instanceToMap)
        {
            int value;
            Int32.TryParse(instanceToMap, out value);
            return value;
        }
    }

    /// <summary>
    /// Convert double to string
    /// </summary>
    public class DoubleToStringMapper : IMapper<double, string>
    {
        public string Map(double instanceToMap)
        {
            return instanceToMap.ToString();
        }
    }

    /// <summary>
    /// Convert B to string
    /// </summary>
    public class MapperOfBToString : IMapper<B, string>
    {
        public string Map(B instanceToMap)
        {
            return instanceToMap.Foo;
        }
    }

    public class A : B, IA { }
    public class C { }
    public interface IA { }

    public class B : C, IB
    {
        public string Foo { get; set; }
    }

    public interface IB
    {
        string Foo { get; set; }
    }
}

Last edited Dec 24, 2016 at 6:06 PM by Manu404, version 13