The Load method may be useful for this, so you do not rewrite the link, but set all the properties of the old object. Here is the general extension method that I just wrote that assigns all writable properties, it is very crude:
public static class ExtensionMethods { public static void Load<T>(this T target, Type type, T source, bool deep) { foreach (PropertyInfo property in type.GetProperties()) { if (property.CanWrite && property.CanRead) { if (!deep || property.PropertyType.IsPrimitive || property.PropertyType == typeof(String)) { property.SetValue(target, property.GetValue(source, null), null); } else { object targetPropertyReference = property.GetValue(target, null); targetPropertyReference.Load(targetPropertyReference.GetType(), property.GetValue(source, null), deep); } } } } }
Then you can call
item.Load(item.GetType(), currentDevice, true); //false for shallow loading
to assign all values ββ(if they are properties).
Edit: Made the method recursive to call Load for properties that do not have a primitive type or value type (or string). Probably in some cases still wrong.
You can also add bool deep to the method and control if it should load heavily, if necessary. (Just add || !deep to this long if statement)
Note. Of course, you can also rewrite the reference to the object and use reflection to raise the PropertyChanged event for all the various properties, if you prefer. In any case, you do not need to manually process each property.
Edit2: Since PropertyInfo.GetValue returns an object , my previous code did not load recursively, unfortunately, with this you need to explicitly pass the type, see revisions for the old version.
Edit3: For ways to do this work without a type reference, see this highlighted question I asked. However, this does not apply to other problems, such as circular references and properties that enumerate objects.