L
Lars Moastuen
Hi!
I'm currently playing around with a project where I need to know if an
object (any object) has been altered since last check. I need this to know
when an object needs to be saved... My idea was to represent the object as
a byte-array and then make a MD5-hash out of that byte[] (not very
efficient though - but that won't really be a big problem here)... I guess
that works fine as long as the object I need to check for updates doesn't
contain any pointers to other objects, because I do not want changes in
"sub-objects" to affect the state of "this" object, as the "sub-object"
will be handled seperatly. The way I thought this could be done would be
to take the address of the sub-object instead of the content of that
object... I'll try to explain with an example:
class SomeClass
{
private int aInt; // Changes should be detected
private String aString; // Changes should be detected
private Object aObject; // Changes to aObject should NOT be detected,
only changes in address of aObject
}
I've tried using the &-operator to get the address of aObject, but that
just gives:
"CS0208: Cannot take the address or size of a variable of a managed type
('object')"
so that won't work...
Does anyone have any ideas on how I can detect changes to an object
without having to write code in all methods changing an object?
Help appreciated,
Lars Moastuen
I'm currently playing around with a project where I need to know if an
object (any object) has been altered since last check. I need this to know
when an object needs to be saved... My idea was to represent the object as
a byte-array and then make a MD5-hash out of that byte[] (not very
efficient though - but that won't really be a big problem here)... I guess
that works fine as long as the object I need to check for updates doesn't
contain any pointers to other objects, because I do not want changes in
"sub-objects" to affect the state of "this" object, as the "sub-object"
will be handled seperatly. The way I thought this could be done would be
to take the address of the sub-object instead of the content of that
object... I'll try to explain with an example:
class SomeClass
{
private int aInt; // Changes should be detected
private String aString; // Changes should be detected
private Object aObject; // Changes to aObject should NOT be detected,
only changes in address of aObject
}
I've tried using the &-operator to get the address of aObject, but that
just gives:
"CS0208: Cannot take the address or size of a variable of a managed type
('object')"
so that won't work...
Does anyone have any ideas on how I can detect changes to an object
without having to write code in all methods changing an object?
Help appreciated,
Lars Moastuen
