在以下简单的场景中,为什么TestMethod1的输出是“test”,而TestMethod2的输出是null?此外,如果您更改顺序并首先运行TestMethod2,则两种方法都将输出null。
我刚开始使用AutoMapper,并且没有太多经验,我真的需要让这个方法(带有对象作为参数)起作用。可以有人请解释一下为什么会这样工作,以及我该怎么办?
我刚开始使用AutoMapper,并且没有太多经验,我真的需要让这个方法(带有对象作为参数)起作用。可以有人请解释一下为什么会这样工作,以及我该怎么办?
public partial class TestClass
{
public string Test { get; set; }
}
class Program
{
static void Main(string[] args)
{
TestMethod1();
TestMethod2(new { Test = "test" });
}
public static void TestMethod1()
{
TestClass test = new TestClass();
Mapper.DynamicMap(new { Test = "test" }, test);
Console.Out.WriteLine(test.Test);
}
public static void TestMethod2(object obj)
{
TestClass test = new TestClass();
Mapper.DynamicMap(obj, test);
Console.Out.WriteLine(test.Test);
}
}