ValueInjecter问题

使用AutoMapper后,我在这个网站上遇到了ValueInjecter。我正在尝试,但我被困在可能是一个非常简单的场景。 但在我深入研究代码示例之前,是否有人知道ValueInjecter是否在中等信任的Web环境中工作? (像Godaddy?) 好的,到代码!我有以下型号:
public class NameComponent 
{
    public string First { get; set; }
    public string Last { get; set; }
    public string MiddleInitial { get; set; }
}
public class Person
{
    public NameComponent Name { get; set; }
}
我要映射到以下DTO:
public class PersonDTO : BaseDTO
{
    private string _firstName;
    public string FirstName
    {
        get { return _firstName; }
        set { NotifyPropertyChanged(() => FirstName, ref _firstName, value); }
    }

    private string _middleInitial;
    public string MiddleInitial
    {
        get { return _middleInitial; }
        set { NotifyPropertyChanged(() => MiddleInitial, ref _middleInitial, value); }
    }

    private string _lastName;
    public string LastName
    {
        get { return _lastName; }
        set { NotifyPropertyChanged(() => LastName, ref _lastName, value); }
    }
}
因此,当我想从模型映射到DTO时,我需要一个Model.Name.First - > DTO.FirstName 从DTO到Model I时需要FirstName - > Name.First。根据我的理解,这不是一个简单的Flatten / UnFlatten,因为这些单词也会反转,即:FirstName< - > Name.First。所以名字和姓氏可以使用相同的规则,但是MiddleInitial呢? Model.Name.MiddleInitial - > DTO.MiddleInitial。 我看到有一些插件,但它们似乎没有做我想要的。还有其他人遇到过这种情况吗?     
已邀请:
基本的想法是我匹配
Name
FirstName
,我把它作为一个支点,并且在通常将值设置为一个(FirstName)属性的方法中,我将它设置为3个属性 - 这是为
FromNameComp
ToNameComp
我匹配相同的属性,但我从3中取值并创建一个并设置它
    public class SimpleTest
    {
        [Test]
        public void Testit()
        {
            var p = new Person { Name = new NameComponent { First = "first", Last = "last", MiddleInitial = "midd" } };
            var dto = new PersonDTO();
            dto.InjectFrom<FromNameComp>(p);

            Assert.AreEqual(p.Name.First, dto.FirstName);
            Assert.AreEqual(p.Name.Last, dto.LastName);
            Assert.AreEqual(p.Name.MiddleInitial, dto.MiddleInitial);

            var pp = new Person();
            pp.InjectFrom<ToNameComponent>(dto);

            Assert.AreEqual(dto.LastName, pp.Name.Last);
            Assert.AreEqual(dto.FirstName, pp.Name.First);
            Assert.AreEqual(dto.MiddleInitial, pp.Name.MiddleInitial);

        }

        public class FromNameComp : ConventionInjection
        {
            protected override bool Match(ConventionInfo c)
            {
                return c.SourceProp.Name == "Name" && c.SourceProp.Type == typeof(NameComponent)
                    && c.TargetProp.Name == "FirstName"
                       && c.SourceProp.Value != null;
            }

            protected override object SetValue(ConventionInfo c)
            {
                dynamic d = c.Target.Value;
                var nc = (NameComponent)c.SourceProp.Value;
                //d.FirstName = nc.First; return nc.First does this
                d.LastName = nc.Last;
                d.MiddleInitial = nc.MiddleInitial;
                return nc.First;
            }
        }

        public class ToNameComponent : ConventionInjection
        {
            protected override bool Match(ConventionInfo c)
            {
                return c.TargetProp.Name == "Name" && c.TargetProp.Type == typeof(NameComponent)
                       && c.SourceProp.Name == "FirstName";
            }

            protected override object SetValue(ConventionInfo c)
            {
                dynamic d = c.Source.Value;
                var nc = new NameComponent { First = d.FirstName, Last = d.LastName, MiddleInitial = d.MiddleInitial };
                return nc;
            }
        }

        public class NameComponent
        {
            public string First { get; set; }
            public string Last { get; set; }
            public string MiddleInitial { get; set; }
        }

        public class Person
        {
            public NameComponent Name { get; set; }
        }

        public class PersonDTO
        {
            public string FirstName { get; set; }
            public string MiddleInitial { get; set; }
            public string LastName { get; set; }
        }
}
  但在我深入研究代码示例之前,   有没有人知道ValueInjecter   适用于中等信任网站   环境? (像Godaddy?) 它不使用reflection.emit所以它应该工作     

要回复问题请先登录注册