Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Need to traverse an object structure using Reflection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Bordeman - 18 Mar 2008 18:05 GMT
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.
Chris Bordeman - 18 Mar 2008 18:16 GMT
Note I haven't written the traversal code, need whatever help I can get with
that.  Thanks again.

> Hi all.
>
[quoted text clipped - 8 lines]
>
> Thanks.
Ben Voigt [C++ MVP] - 18 Mar 2008 18:41 GMT
> 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?

>> Hi all.
>>
[quoted text clipped - 8 lines]
>>
>> Thanks.
Chris Bordeman - 18 Mar 2008 21:17 GMT
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.

>> Note I haven't written the traversal code, need whatever help I can
>> get with that.  Thanks again.
[quoted text clipped - 33 lines]
>>>
>>> Thanks.
Rene - 18 Mar 2008 22:31 GMT
>  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".
Chris Bordeman - 19 Mar 2008 18:11 GMT
Correct.

>>  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".

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.