Is it possible to put a reference to an object inside of a class? If so,
what is the syntax? The reason I want to do this is so that I can make a
copy of the original object, make modifications to the copy and then, if the
modifications are acceptable, reload the original object with the contents
of the modified copy object.
If I were doing this in C++, I'd just pass in a pointer to the original
object, copy its contents in the constructor to a temporary object, operate
on the temp object and, upon final confirmation, copy the contents of the
temp object to the original object through the passed in pointer. I'm sure
that something like this is possible in C# but I just can't get the syntax
right. How does one hang on to the original reference? I don't see how to
declare a data member as a reference. Granted, I can get around that by
doing a copy from the temp object back to the original object in the
caller's code but I want to encapsulate everything in the class and not
force the caller to do anything more than necessary.
Example:
Assume that O1 is the object that is to be modified.
Assume that C1 is the class that is responsible for handling the
modification.
When C1 is created, it gets a reference to the original O1.
The original O1 is copied into a temporary O1 inside of C1.
C1 has two possible exit conditions.
Exit successful - the contents of the modified O1 are copied to the original
O1.
Exit failure - the original O1 is left unmodified.
--
Richard Lewis Haggard
www.Haggard-And-Associates.com