我得到了这个测试:
[Fact]
public void EverythingIsMappedJustFine(){
new AutoMapperTask().Execute();
Mapper.AssertConfigurationIsValid();
}
它抛出了一个有点奇怪的异常:
不幸的是 - 我无法在较小的规模上重现这一点,也无法弄清楚到底发生了什么。
什么是强制运算符?
This 可能有用。但是我没有提取和简化必要的信息位。
最佳答案
我仍然不知道强制操作符到底是什么,但至少 - 我解决了我的问题找到了原因。
经过一些 automapper 调试能够重现问题:
namespace mappertest
{
using AutoMapper;
using NUnit.Framework;
[TestFixture]
public class FooFacts
{
[Test]
public void MapToFizz()
{
Mapper.Initialize(c => c.AddProfile(new FooProfile()));
var foo = new Foo { Bar = "BarValue" };
var fooModel = Mapper.Map<Foo, FooModel>(foo);
Assert.AreEqual("BarValue", fooModel.Bar);
}
}
public class FooProfile : Profile
{
protected override void Configure()
{
CreateMap<Foo, FooModel>();
}
}
public class Foo
{
public string Bar { get; set; }
public void Fizz() { }
}
public class FooModel
{
public string Bar { get; set; }
public FizzModel Fizz { get; set; }
}
public class FizzModel { }
}
事实证明非常简单 - 源具有与目标属性一样命名的方法。
关于C# 强制运算符?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3891438/