2

是否可以从这样的东西注入:

public class DomainEntity
{
    public Resource DescriptionResource { get; set; }
}

public class Resource
{
    public List<ResourceLocalization> Localizations { get; set; }
}

public class ResourceLocalization
{
    public string Culture { get; set; }
    public string Value { get; set; }
}

像这样:

public class DomainEntityViewModel
{
    public string Description { get; set; }
}

(DomainEntity.DescriptionResource.Localizations.First().Value => DomainEntityViewModel.Description)

使用值注入器。

谢谢你!

4

1 回答 1

2

你可以使用这个注入:

    public class MyInj : ConventionInjection
    {
        protected override bool Match(ConventionInfo c)
        {
            return c.TargetProp.Name == c.SourceProp.Name 
            && c.TargetProp.Type == typeof (string) 
            && c.SourceProp.Type == typeof (List<ResourceLocalization>);
        }
        protected override object SetValue(ConventionInfo c)
        {
            return ((List<ResourceLocalization>) c.SourceProp.Value).First().Value;
        }
    }
于 2012-05-12T06:02:51.137 回答