469,304 Members | 2,192 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,304 developers. It's quick & easy.

Reflection of properties.

Ok, I've heard all about reflection.
How do I print out the results for all the properties on this object:

System.Reflection.Assembly.GetExecutingAssembly(). GetName()

I don't want a list of properties, but a list of values for the properties.
Thanks

--
Frank
Nov 15 '05 #1
4 21473
PropertyInfo objects contain a method called GetValue(...) in which you pass
the object instance.

Jon

"Frank Rizzo" <no****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Ok, I've heard all about reflection.
How do I print out the results for all the properties on this object:

System.Reflection.Assembly.GetExecutingAssembly(). GetName()

I don't want a list of properties, but a list of values for the properties. Thanks

--
Frank

Nov 15 '05 #2
Jon Davis wrote:
PropertyInfo objects contain a method called GetValue(...) in which you pass
the object instance.
I am not familiar with that object. Could you provide an example and/or
how to loop through all the properties?

Jon

"Frank Rizzo" <no****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Ok, I've heard all about reflection.
How do I print out the results for all the properties on this object:

System.Reflection.Assembly.GetExecutingAssembly( ).GetName()

I don't want a list of properties, but a list of values for the


properties.
Thanks

--
Frank



Nov 15 '05 #3
(Untested...)
using System.Reflection;

......

Hashtable PropertiesOfMyObject = new HashTable();
Type t = myObject.GetType();
PropertyInfo[] pis = t.GetProperties();
for (int i=0; i<pis.Length; i++) {
PropertyInfo pi = (PropertyInfo)pis.GetValue(i);
PropertiesOfMyObject.Add(pi.Name, pi.GetValue(myObject, new object[]
{}));
}

HTH,
Jon
"Frank Rizzo" <no****@nospam.com> wrote in message
news:ex**************@TK2MSFTNGP12.phx.gbl...
Jon Davis wrote:
PropertyInfo objects contain a method called GetValue(...) in which you pass the object instance.


I am not familiar with that object. Could you provide an example and/or
how to loop through all the properties?

Jon

"Frank Rizzo" <no****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Ok, I've heard all about reflection.
How do I print out the results for all the properties on this object:

System.Reflection.Assembly.GetExecutingAssembly( ).GetName()

I don't want a list of properties, but a list of values for the


properties.
Thanks

--
Frank


Nov 15 '05 #4
You are the man. I haven't tested it, but the code makes sense.

Jon Davis wrote:
(Untested...)
using System.Reflection;

.....

Hashtable PropertiesOfMyObject = new HashTable();
Type t = myObject.GetType();
PropertyInfo[] pis = t.GetProperties();
for (int i=0; i<pis.Length; i++) {
PropertyInfo pi = (PropertyInfo)pis.GetValue(i);
PropertiesOfMyObject.Add(pi.Name, pi.GetValue(myObject, new object[]
{}));
}

HTH,
Jon
"Frank Rizzo" <no****@nospam.com> wrote in message
news:ex**************@TK2MSFTNGP12.phx.gbl...
Jon Davis wrote:
PropertyInfo objects contain a method called GetValue(...) in which you
pass
the object instance.


I am not familiar with that object. Could you provide an example and/or
how to loop through all the properties?

Jon

"Frank Rizzo" <no****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl. ..
Ok, I've heard all about reflection.
How do I print out the results for all the properties on this object:

System.Reflection.Assembly.GetExecutingAssembl y().GetName()

I don't want a list of properties, but a list of values for the

properties.
Thanks

--
Frank




Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Rlrcstr | last post: by
3 posts views Thread by HL | last post: by
1 post views Thread by Eric | last post: by
3 posts views Thread by groovyjman21 | last post: by
5 posts views Thread by DesCF | last post: by
17 posts views Thread by raylopez99 | last post: by
6 posts views Thread by Cralis | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.