473,397 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

building a treeview from an object graph (reflection)

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
Nov 22 '05 #1
1 2448
>public TreeNode BuildNode(ref object o)

Why is o passed by ref?

treenode.Text = typeof(o).Name;
That should probably be

treenode.Text = o.GetType().Name;

if (typeof(o).GetInterface("System.IEnumerable",true) )
if ( o is IEnumerable )

foreach(MemberInfo m in typeof(o).GetProperties(BindingFlags.Public))
tn.Add(BuildNode(ref mi.???); // << trouble here


foreach(PropertyInfo p in
o.GetType().GetProperties(BindingFlags.Public))
if ( p.GetIndexParameters().Length == 0 )
tn.Add(BuildNode(p.GetValue(o, null)));

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
1
by: Rein Petersen | last post by:
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...
3
by: Steve | last post by:
Visual Studio 2003 .NET / C# I have a treeview object on a form which acts as the main menu controller for my application. the treeview is always in sight, and the form it is on acts as the...
0
by: Rein Petersen | last post by:
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...
1
by: Raveendra M | last post by:
Hi! I am working with ASP.NET application. In my page I am creating one Application Domain and in that domain I am calling my DLL. Using the methods of the dll. And unloading the Application...
6
by: solex | last post by:
Hello, I am trying to use serialization to copy objects. The object in question "Institution" inherits from a parent object "Party" both are marked as <Serializable()>. Initially I can copy an...
4
by: Henry | last post by:
Does anybody have a real-world sample of buiding a treeview control using data from database tables? All the sample code I have found either builds the treeview manually or uses a file directory...
4
by: colin | last post by:
Hi, I wish to display and edit 3 collections of different object types, each object type also has a collection of the other 2 types, such that if one object contains another then the reverse is...
4
by: Man4ish | last post by:
namespace ve/////////////////ve.h { struct VertexProperties { std::size_t index; boost::default_color_type color; }; }...
2
by: Man4ish | last post by:
I have created Graph object without vertex and edge property.It is working fine. #include <boost/config.hpp> #include <iostream> #include <vector> #include <string> #include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.