473,511 Members | 10,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

diagram a class structure with reflection

Are there any tools that will take an existing assembly and generate a
class hierarchy from it? It seems like the kind of thing that would be
possible with reflection, but I don't know enough about that namespace
to tackle this.

Lee Crabtree
Aug 30 '06 #1
3 1629
You can use reflection to iterrate through methods, properties, etc. Using
this information, you could easily add these items as entries in a ListView
or a TreeView (then serialize it to XML, if so desired).

Here's a quick snippet that gets methods and properties from a TextBox
object, and adds them to a ListView (Be sure to include the System.Reflection
namespace):

private void button1_Click(object sender, System.EventArgs e)
{
Type t = typeof(TextBox);
//Get method info for an object
MethodInfo[] mI = t.GetMethods();
for (int x=0; x<mI.Length; x++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = mI[x].Name;
this.listBox1.Items.Add(lvi);
}
//Get properties for an object
PropertyInfo[] pI = t.GetProperties();
for (int x=0; x<pI.Length; x++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = pI[x].Name;
this.listBox1.Items.Add(lvi);
}
}

Hope it helps.

--
"Quae narravi, nullo modo negabo."
"Lee Crabtree" wrote:
Are there any tools that will take an existing assembly and generate a
class hierarchy from it? It seems like the kind of thing that would be
possible with reflection, but I don't know enough about that namespace
to tackle this.

Lee Crabtree
Aug 30 '06 #2
What about subclass/superclass info? Is that just stored as a property
of a Type? That's the major thing I want to see to begin with.

Lee Crabtree

UsualDosage wrote:
You can use reflection to iterrate through methods, properties, etc. Using
this information, you could easily add these items as entries in a ListView
or a TreeView (then serialize it to XML, if so desired).

Here's a quick snippet that gets methods and properties from a TextBox
object, and adds them to a ListView (Be sure to include the System.Reflection
namespace):

private void button1_Click(object sender, System.EventArgs e)
{
Type t = typeof(TextBox);
//Get method info for an object
MethodInfo[] mI = t.GetMethods();
for (int x=0; x<mI.Length; x++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = mI[x].Name;
this.listBox1.Items.Add(lvi);
}
//Get properties for an object
PropertyInfo[] pI = t.GetProperties();
for (int x=0; x<pI.Length; x++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = pI[x].Name;
this.listBox1.Items.Add(lvi);
}
}

Hope it helps.
Aug 30 '06 #3
Using the Type object, you should be able to locate anything and everything
you need regarding the object in question. It has methods for accessing
Assembly info, Interfaces, Fields, Properties, Methods, Attributes, Events,
Default Constructors...You name it, it contains it.

Just start by declaring a Type object of the type of object you are looking
to diagram: Type t = typeof(myObject); Then, just do a "t.", and the
Intellisense will give you an idea of what it can get for you.

If you're looking to diagram a class library, alternatively, I believe you
can just use Visio to diagram the class, which works well for visual
presentations.

--
"Quae narravi, nullo modo negabo."
"Lee Crabtree" wrote:
What about subclass/superclass info? Is that just stored as a property
of a Type? That's the major thing I want to see to begin with.

Lee Crabtree

UsualDosage wrote:
You can use reflection to iterrate through methods, properties, etc. Using
this information, you could easily add these items as entries in a ListView
or a TreeView (then serialize it to XML, if so desired).

Here's a quick snippet that gets methods and properties from a TextBox
object, and adds them to a ListView (Be sure to include the System.Reflection
namespace):

private void button1_Click(object sender, System.EventArgs e)
{
Type t = typeof(TextBox);
//Get method info for an object
MethodInfo[] mI = t.GetMethods();
for (int x=0; x<mI.Length; x++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = mI[x].Name;
this.listBox1.Items.Add(lvi);
}
//Get properties for an object
PropertyInfo[] pI = t.GetProperties();
for (int x=0; x<pI.Length; x++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = pI[x].Name;
this.listBox1.Items.Add(lvi);
}
}

Hope it helps.
Aug 30 '06 #4

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

Similar topics

5
3877
by: Bob Alston | last post by:
I have a where used utility that shows where any table or query is used - in a query, form or table. I would like some kind of diagram that shows these relations. I have some reports that...
0
936
by: Craig | last post by:
I need to display a hierarchical diagram of a group of 300 objects, organized kind of like a class structure. What's the best way to do this in ASP.net? I'm even open to 3rd part asp products if...
1
2611
by: Christopher A. Kelly | last post by:
I need to figure out how to control any 3rd party application by simulating mouse click and key presses. I need to take a partial window title and get the handle then be able to send the necessary...
0
1162
by: Qwert | last post by:
Hello, why does the following code work for a CLASS, but not for a STRUCTURE? (The first MsgBox returns '0,0', but I expected it to be '100,0'.) (The second MsgBox returns 'Hello', as...
0
1441
by: Rajesh | last post by:
Hi, I have a vc++ com component all the business validations are done through the component.Im using interop to communicate with the com component through ..Net(C#) I want to design a class...
4
2004
by: sameerishah | last post by:
Hi, I have a need to read the fields of a structure in a for loop. for eg. the structure looks like: str.a1, str.a2, str.a3 where a1, a2, a3 are of type string How do I do it? Thanks in...
4
2382
by: Steve Goldman | last post by:
Even asking this question probably demonstrates that I have a fundamental misunderstanding of how values and references work in C#, but here goes: I'd like to assign a reference to an arbitrary...
1
2444
by: Oskar Bennet | last post by:
Hi everybody, I am supposed to draw a simple UML diagram for a very small project that consists of less than a dozen classes. I have never been working with UML before, I have read some tutorials...
1
4672
by: Jennifer Jazz | last post by:
My question is regarding the mapping of Class diagram to the C++ coding. There are 3 realtions in Class diagram 1) Assosication 2) Composition 3) Aggregation (Weak Composition). ...
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7148
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...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5673
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
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.