[Mono-list] Retrieving the Properties of a class at runtime

Joe Audette joe_audette@yahoo.com
Thu, 30 Dec 2004 07:06:24 -0800 (PST)


--0-116528652-1104419184=:40894
Content-Type: text/plain; charset=us-ascii

Something like this should give an idea of how to get started
 

public static void WriteProperties(string AssemblyPath)

{

Assembly assembly = Assembly.LoadFrom(AssemblyPath);

foreach(Type type in assembly.GetTypes())

{

foreach(PropertyInfo propertyInfo in type.GetProperties())

{

Console.WriteLine(propertyInfo.Name);



}

}

}

Best Regards,

Joe


Shawn Vose <mono@programmerforrent.com> wrote:
Can someone direct me to documentation on how to iterate over only the 
properties in a class at runtime. I have a class that is nothing but 
properties and instead of typing out 
Console.WriteLine(someObject.someProperty) it would rather iterate over 
the available properties.

Ist this where System.Refelection comes into play?

_______________________________________________
Mono-list maillist - Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list


joe_audette@yahoo.com
http://www.joeaudette.com
http://www.mojoportal.com
--0-116528652-1104419184=:40894
Content-Type: text/html; charset=us-ascii

<DIV>Something like this should give an idea of how to get started</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=#0000ff size=2>
<P>public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>static</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>void</FONT><FONT size=2> WriteProperties(</FONT><FONT color=#0000ff size=2>string</FONT><FONT size=2> AssemblyPath)</P>
<P>{</P>
<P>Assembly assembly = Assembly.LoadFrom(AssemblyPath);</P>
<P></FONT><FONT color=#0000ff size=2>foreach</FONT><FONT size=2>(Type type </FONT><FONT color=#0000ff size=2>in</FONT><FONT size=2> assembly.GetTypes())</P>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>foreach</FONT><FONT size=2>(PropertyInfo propertyInfo </FONT><FONT color=#0000ff size=2>in</FONT><FONT size=2> type.GetProperties())</P>
<P>{</P>
<P>Console.WriteLine(propertyInfo.Name);</P>
<P></P>
<P>}</P>
<P>}</P>
<P>}</P>
<P>Best Regards,</P>
<P>Joe</P></FONT><BR><BR><B><I>Shawn Vose &lt;mono@programmerforrent.com&gt;</I></B> wrote:</DIV>
<BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">Can someone direct me to documentation on how to iterate over only the <BR>properties in a class at runtime. I have a class that is nothing but <BR>properties and instead of typing out <BR>Console.WriteLine(someObject.someProperty) it would rather iterate over <BR>the available properties.<BR><BR>Ist this where System.Refelection comes into play?<BR><BR>_______________________________________________<BR>Mono-list maillist - Mono-list@lists.ximian.com<BR>http://lists.ximian.com/mailman/listinfo/mono-list<BR></BLOCKQUOTE><BR><BR>joe_audette@yahoo.com<br>http://www.joeaudette.com<br>http://www.mojoportal.com
--0-116528652-1104419184=:40894--