سؤال

is it possible to inject from something like this :

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; }
}

to something like this:

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

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

using ValueInjecter.

Thank You!

هل كانت مفيدة؟

المحلول

you could use this injection :

    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;
        }
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top