Git Product home page Git Product logo

safemapper's People

Contributors

unger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

safemapper's Issues

SafeMapper no longer maps nullable to nullable

It seems the latest update introduced a new regression for mapping between nullable types. These codes used to work in previous version (2.0.112), but failed and throws exception in latest version (2.0.118):

SafeMap.Convert<int?, int?>(42);
SafeMap.Convert<bool?, bool?>(true);
SafeMap.Convert<Guid?, Guid?>(Guid.NewGuid());
SafeMap.Convert<DateTime?, DateTime?>(DateTime.Now);
SafeMap.Convert<TimeSpan?, TimeSpan?>(TimeSpan.FromDays(28));

Issue converting double.MaxValue

Hi!

seems like SafeMapper has issues when converting edge cases (i.e. MaxValue for double)
The test bellow fails.

[TestMethod]
public void SafeMapTest()
{
double d = double.MaxValue;
string value = d.ToString("R");
var result = SafeMap.Convert<string, double>(value);
Assert.AreEqual(d, result);
}

Any ideas?

Thanks
Alexander

Can't map items from diferent levels

I've created 2 tests that reproduce the issue, basically I can't map properties from diferente depths in the classes. Here are the 2 tests that fail and illustrate the issue:

    [TestMethod]
    public void SafeMapper_CreateMap_PersonToPersonPortugueseWithComplexTypeDiferentLevelsMapping()
    {
        SafeMap.CreateMap<Person, PersonPortuguese>(
            cfg =>
            {
                cfg.Map(x => x.StreetName, x => x.Morada.NomeDaRua);
            });

        var person = new Person
        {
            StreetName = "Microsoft Street",
        };
        var result = SafeMap.Convert<Person, PersonPortuguese>(person);

        Assert.AreEqual(person.StreetName, result.Morada.NomeDaRua);
    }

    [TestMethod]
    public void SafeMapper_CreateMap_PersonPortugueseToPersonWithComplexTypeDiferentLevelsMapping()
    {
        SafeMap.CreateMap<PersonPortuguese, Person>(
            cfg =>
            {
                cfg.Map(x => x.Morada.NomeDaRua, x => x.StreetName);
            });


        var person = new PersonPortuguese
        {
            Morada = new AddressPortuguese()
            {
                NumeroDePorta = 12,
                NomeDaRua = "Microsoft Street",
                CodigoPostal = "1234-567"
            }
        };
        var result = SafeMap.Convert<PersonPortuguese, Person>(person);

        Assert.AreEqual(person.Morada.NomeDaRua, result.StreetName);
    }

    public class PersonPortuguese
    {
            public AddressPortuguese Morada { get; set; }
    }
    public class Person
    {
            public string StreetName { get; set; }
    }
    public sealed class Address
    {
            public string StreetName { get; set; }
            public int DoorNumber { get; set; }
            public string ZipCode { get; set; }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.