This is just a 'out-of-curiosity' question, so I can't provide a real world example based on a current problem, but a little dummy code should suffice. What I'm wondering is if there is a straight-forward (and especially fast) way to map an instance of an object to 'this' (a current instance of the exact same type, with access to private members etc.)
public class MyObject {
public MyObject(MyObject other) {
// of course, won't work
this = other;
}
}
All examples and how-to's I've seen take excessive use of reflection, even building up complete expression trees or using frameworks like Automapper, all with their own limitations when the idea seems 'fairly trivial'. Why isn't it just possible to copy over all pointers/references etc. from one place in memory to another, given that the allocated space etc. is exactly the same?
Aucun commentaire:
Enregistrer un commentaire