unger / safemapper Goto Github PK
View Code? Open in Web Editor NEWException free and extremly fast object mapper
License: MIT License
Exception free and extremly fast object mapper
License: MIT License
When using this mapper's nuget packages with Strong Named libraries users will hit a wall because of lack of a assembly public key...
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));
Aspnet 5 needs dnx451 and dnxcore50 targets.
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
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; }
}
If you create a map from an int to a nullable int it will result in 0, 2 of the same types works fine and nullable int to int also works fine.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.