fluentsprings / ExpressMapper

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

.Member and .Function are ignored when members have the same name but differ in case #73

Closed mattijs79 closed 8 years ago

mattijs79 commented 8 years ago
using ExpressMapper;

using NUnit.Framework;

namespace test
{
    [TestFixture]
    public class Test
    {
        [Test]
        public void TestMember()
        {
            var from = new From { Test = "hi" };

            Mapper.Reset();

            Mapper.Register<From, To>()
                .Member(dest => dest.test, src => "there");

            var to = Mapper.Map<From, To>(from);

            // Fails
            Assert.That(to.test, Is.EqualTo("there"));
        }

        [Test]
        public void TestFunction()
        {
            var from = new From { Test = "hi" };

            Mapper.Reset();

            Mapper.Register<From, To>()
                .Function(dest => dest.test, src => "there");

            var to = Mapper.Map<From, To>(from);

           // Fails
            Assert.That(to.test, Is.EqualTo("there"));
        }

        private class From
        {
            public string Test { get; set; }
        }

        private class To
        {
            public string test { get; set; }
        }
    }
}
anisimovyuriy commented 8 years ago

Dear mattijs79,

Thanks for your valuable input! Actually it wasn't a bug but feature :) - regarding case-insensitive. But do you have really such a case where you use the same name with different cases?

Thanks, Yuriy

mattijs79 commented 8 years ago

Dear Yuriy

Thanks for your quick response

I'm mapping properties from a service reference to a third party webservice to my own model's properties. The code generated from the wsdl has properties starting with lower case while I prefer to have my model's properties to start with uppercase. I was pleasantly suprised to find out that ExpressMapper mapped these correctly to each other, but then I encountered this bug/feature.

What I would expect is that either mapping case-insensitive would work the same as case-sensitive, or not at all.

Thanks, Mattijs

anisimovyuriy commented 8 years ago

Dear mattijs79,

Thanks a lot for your response! I'll fix it for you.

Gratefully Yours, Yuriy

mattijs79 commented 8 years ago

Thanks a lot Yuriy. And happy new year ;-)

anisimovyuriy commented 8 years ago

Happy new year :) - even if it is late!

Fixed and will be included in 1.8 release. To use that feature you please follow guide: 1) By default all members' mappings are case insensitive 2) To turn on global configuration for sensitivity (All registration and mappings even dynamic) use Mapper.MemberCaseSensitiveMap(true); 3) For local (per registration) use:

Mapper.Register<TypoCase, TypoCaseViewModel>()
                .CaseSensetiveMemberMap(false);

4) Local case always overrides Global