I have two instances of the same class (config). The class has many properties, and some properties are other classes/enums/arrays.
The first instance of the class is a fully populated config. Every property is filled here.
The second instance of the class is the config of what I want to change.

How can I merge two instances so that the first instance gets the properties of the second one?

```
public void CopyValues<T>(T target, T source)
{
    Type t = typeof(T);

    var properties = t.GetProperties().Where(prop => prop.CanRead && prop.CanWrite);

    foreach (var prop in properties)
    {
        var value = prop.GetValue(source, null);
        if (value != null)
             prop.SetValue(target, value, null);
    }
}

```

I tried to do it with this code, but it doesn't work if one of the instance properties is a subclass.
For example:

```
public class Person
    {
        public string Id { get; set; }

        public string Name { get; set; }

        public Nationality? Nationality { get; set; } //enum

        public Address Address { get; set; } //class
    }

public class Address
    {
        public string Country { get; set; }

        public string City { get; set; } 
    }

```

Here is what I want:

```
public void UpdatePerson()
        {
            Person actualPerson = GetPerson(); //full config

            Person newConfig = new Person()
            {
                Address = new Address()
                {
                    City = "Berlin"
                }
            }

            CopyValues(actualPerson, newConfig);
        }

```