我有这个简单的代码:
using Omu.ValueInjecter;
namespace InjectionTest
{
public class Partner
{
public int Id { get; set; }
public string Name { get; set; }
public City City { get; set; }
}
public class City
{
public int Id { get; set; }
public string Name { get; set; }
}
public class PartnerViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public string CityName { get; set; }
}
class Program
{
static void Main(string[] args)
{
var city = new City()
{
Id = 1,
Name = "Athens"
};
var partner = new Partner()
{
Id = 1,
Name = "Acme d.o.o.",
City = city
};
var vm = new PartnerViewModel();
vm.InjectFrom(partner);
}
}
}
据我所知,Valueinjector按类名+属性名映射复杂的对象图。我期望vm对象属性CityName为"雅典"注射后,它是空的。我想我错过了一些东西。帮助赞赏。