fluentsprings / ExpressMapper

Mapping .Net types
http://www.expressmapper.org
Other
310 stars 65 forks source link

RegisterCustom and MapExists #140

Open nicolasn79 opened 7 years ago

nicolasn79 commented 7 years ago

Mapper.MapExists() method return false for Register made using RegisterCustom<T, TN>(Func<T, TN> mapFunc) method. Is it the normal behaviour ?

See code sample: using System; using ExpressMapper; using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace RegisterCustomIssue { enum CHAR { A, B, C }

enum NBR { ONE, TWO, THREE }

public static class RegisterMapper { public static void Register() { if (!Mapper.MapExists(typeof(CHAR), typeof(NBR))) { Mapper.RegisterCustom<CHAR, NBR>( src => { switch (src) { case CHAR.A: return NBR.ONE; case CHAR.B: return NBR.TWO; case CHAR.C: return NBR.THREE; default: return NBR.ONE; } } ); } } }

[TestClass] public class UnitTest1 { [TestMethod] public void TestMethod1() { RegisterMapper.Register(); RegisterMapper.Register(); Assert.IsTrue(true); } } }

tigrab-dpl commented 5 years ago

Hello, i am facing the same problem. Ican not detect wether a registartion is done or not. Is there any news? I get following error: System.InvalidOperationException: Mapping from System.Data.DataTable to System.Collections.Generic.List`1[[DPLDataProvider.Models.Model, DPLDataProvider, Version=0.0.9.0, Culture=neutral, PublicKeyToken=null]] is already registered bei ExpressMapper.MappingServiceProvider.RegisterCustom[T,TN,TMapper]() in C:\Source\ExpressMapper\Expressmapper.Shared\MappingServiceProvider.cs:Zeile 999.