Need to traverse an object structure using Reflection

C

Chris Bordeman

Hi all.

I need to generically detect changes in any object from one point to the
next. I can't modify the objects, nor can I use traditional serialization
because the attributes aren't present and would be too slow anyway.

My current approach is to recursively traverse a given object using
Reflection, storing hash values for strings and value types, then do it
again later and compare. Is there a better approach? Maybe someone has
some code that would be helpful?

Thanks.
 
C

Chris Bordeman

Note I haven't written the traversal code, need whatever help I can get with
that. Thanks again.

"Chris Bordeman"
 
B

Ben Voigt [C++ MVP]

Chris said:
Note I haven't written the traversal code, need whatever help I can
get with that. Thanks again.

Your problem definition is incomplete.

How would you treat this (omitting access modifiers):

class SelfReferential
{
string s;
SelfReferential ptr;
}

SelfReferential one = new SelfReferential();
SelfReferential two = new SelfReferential();
SelfReferential three = new SelfReferential();

one.ptr = one;
two.ptr = two;
three.ptr = one;

one.s = two.s = three.s = "some string";

Which of the above should compare equal?
 
C

Chris Bordeman

These are all fairly simple business objects. That situation would not be
supported to self references would be simply be ignored. But the rule is
that the strings and value types must equal eachother in value, not
necessarily be the same object.
 
R

Rene

But the rule is that the strings and value types must equal eachother in
value, not necessarily be the same object.

So I am assuming that these business objects do not override "Equals" right?
Otherwise, this looks to me like the perfect job for "Equals".
 
C

Chris Bordeman

Correct.

Rene said:
So I am assuming that these business objects do not override "Equals"
right? Otherwise, this looks to me like the perfect job for "Equals".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top