PC Review


Reply
Thread Tools Rate Thread

diagram a class structure with reflection

 
 
Lee Crabtree
Guest
Posts: n/a
 
      30th Aug 2006
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?VXN1YWxEb3NhZ2U=?=
Guest
Posts: n/a
 
      30th Aug 2006
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
>

 
Reply With Quote
 
 
 
 
Lee Crabtree
Guest
Posts: n/a
 
      30th Aug 2006
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.
>

 
Reply With Quote
 
=?Utf-8?B?VXN1YWxEb3NhZ2U=?=
Guest
Posts: n/a
 
      30th Aug 2006
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.
> >

>

 
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
Static class association in class diagram? Ole Microsoft C# .NET 0 10th Nov 2008 11:04 AM
Diagram for read-write diagram Salmon Egg Storage Devices 3 7th Oct 2008 11:55 AM
Can't specify a location for new class code file on class diagram>new class dialog? Andy B Microsoft C# .NET 3 14th Feb 2008 02:57 AM
UML class diagram using reflection- Com component Rajesh Microsoft C# .NET 0 26th Jan 2006 08:49 AM
How do I change the Diagram Style (in the Cycle Diagram) to ARROW. =?Utf-8?B?UGFtTA==?= Microsoft Powerpoint 4 24th Mar 2005 06:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:43 AM.