PC Review


Reply
Thread Tools Rate Thread

Building a treeview from object graph (reflection)

 
 
Rein Petersen
Guest
Posts: n/a
 
      10th Feb 2005
Hi all,

I'm toying with reflection to try and build a recursive function that
generates treenodes of a treeview that represent any given object's
graph (of child objects):

public TreeNode BuildNode(ref object o)
{
TreeNode tn;
treenode.Tag = o;
treenode.Text = typeof(o).Name;

if (typeof(o).GetInterface("System.IEnumerable",true))
foreach (object c in o)
tn.Nodes.Add(BuildNode(ref c));
else
foreach(MemberInfo m in typeof(o).GetProperties(BindingFlags.Public))
tn.Add(BuildNode(ref mi.???); // << trouble here
// I really just want access
// to the property from the
// MemberInfo object...
return tn;
}

As you can see, it almost works except I have no way of accessing an
[un?]boxed object's property. I know from reflecting the object's type
that it has the property, but have no way of accessing the property (in
a generic manner) without hardcoding my object types into a bunch of
overloads of 'BuildNode', or having some way-huge switch.

Looking for advice, pointers to documents, creative ideas, etc. that
might get me closer to a solution.

Thanks for all your help,

Rein
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
building a self referencing class using System.Reflection.Emit Darren Microsoft Dot NET Framework 1 31st Mar 2011 10:11 AM
Passing values to object during object instantiation using reflection, Possible? Søren M. Olesen Microsoft C# .NET 4 15th Sep 2006 11:31 AM
report with Graph Ole object, can I manipulate the datasource of the graph by code? Philip Leduc Microsoft Access Reports 1 27th Jun 2005 11:03 AM
report with Graph Ole object, can I manipulate the datasource of the graph by code? Philip Leduc Microsoft Access 0 23rd Jun 2005 12:34 AM
building a treeview from an object graph (reflection) Rein Petersen Microsoft Dot NET 1 10th Feb 2005 10:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:52 AM.