DEV Community

Alexey
Alexey

Posted on

Answer: Apply properties values from one object to another of the same type automatically?

Here's a short and sweet version, since you said both of your objects are of the same type:

foreach (PropertyInfo property in typeof(YourType).GetProperties().Where(p => p.CanWrite)) { property.SetValue(targetObject, property.GetValue(sourceObject, null), null); } 

Top comments (0)