0

I have a problem using ValueInjecter for derived classes:

public class A
{
  public Guid Id { get; set; }
  public string Name { get; set; }
}

public class B : A
{
  public int Age { get; set; }
}

public static void main()
{
  var b = new B()
  {
    Id = Guid.NewGuid(),
    Name = "Test!",
    Age = 47
  };

  var a = new A();

  a.InjectFrom(b);

}

Injecter does not seem to copy the properties of the derived class.

I then tried to use the Clone convention and debugged the different calls to the methods, but I could not even see calls for the properties of the derived class. Only the properties directly on class A were called.

What am I doing wrong?

Best regards, Andreas Kroll

Omu
  • 69,856
  • 92
  • 277
  • 407
nttakr
  • 1,637
  • 15
  • 25
  • Well you can start by showing how you have written your `InjectFrom` method. – Dion V. May 20 '16 at 08:49
  • so the problem is that `a.Age` is not set ? – Omu May 20 '16 at 09:04
  • Since I did not write the InjectFrom method, I cannot show you. You do know that we are talking about ValueInjecter??? – nttakr May 26 '16 at 16:58
  • @Omu, the problem is that Age is copied, but the rest (Id, Name) is not. That is what I am wondering about. If I check which properties are "considered" by using the Clone sample, I only get a call with Age as property. – nttakr May 26 '16 at 16:59
  • Age can't possibly be copied because a is of type A which doesn't have `Age` property, only Id and Name should be copied in your example – Omu May 26 '16 at 17:09

0 Answers0