Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old November 15th, 2005, 05:45 AM
Frank Rizzo
Guest
 
Posts: n/a
Default 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


  #2  
Old November 15th, 2005, 05:45 AM
Jon Davis
Guest
 
Posts: n/a
Default Re: Reflection of properties.

PropertyInfo objects contain a method called GetValue(...) in which you pass
the object instance.

Jon

"Frank Rizzo" <nospam@nospam.com> wrote in message
news:%23B5zhqnTDHA.2228@TK2MSFTNGP11.phx.gbl...[color=blue]
> 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[/color]
properties.[color=blue]
> Thanks
>
> --
> Frank
>
>[/color]


  #3  
Old November 15th, 2005, 05:46 AM
Frank Rizzo
Guest
 
Posts: n/a
Default Re: Reflection of properties.

Jon Davis wrote:[color=blue]
> PropertyInfo objects contain a method called GetValue(...) in which you pass
> the object instance.[/color]

I am not familiar with that object. Could you provide an example and/or
how to loop through all the properties?
[color=blue]
>
> Jon
>
> "Frank Rizzo" <nospam@nospam.com> wrote in message
> news:%23B5zhqnTDHA.2228@TK2MSFTNGP11.phx.gbl...
>[color=green]
>>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[/color]
>
> properties.
>[color=green]
>>Thanks
>>
>>--
>>Frank
>>
>>[/color]
>
>
>[/color]

  #4  
Old November 15th, 2005, 05:46 AM
Jon Davis
Guest
 
Posts: n/a
Default Re: Reflection of properties.

(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" <nospam@nospam.com> wrote in message
news:ex1VtGoTDHA.2128@TK2MSFTNGP12.phx.gbl...[color=blue]
> Jon Davis wrote:[color=green]
> > PropertyInfo objects contain a method called GetValue(...) in which you[/color][/color]
pass[color=blue][color=green]
> > the object instance.[/color]
>
> I am not familiar with that object. Could you provide an example and/or
> how to loop through all the properties?
>[color=green]
> >
> > Jon
> >
> > "Frank Rizzo" <nospam@nospam.com> wrote in message
> > news:%23B5zhqnTDHA.2228@TK2MSFTNGP11.phx.gbl...
> >[color=darkred]
> >>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[/color]
> >
> > properties.
> >[color=darkred]
> >>Thanks
> >>
> >>--
> >>Frank
> >>
> >>[/color]
> >
> >
> >[/color]
>[/color]


  #5  
Old November 15th, 2005, 05:46 AM
Frank Rizzo
Guest
 
Posts: n/a
Default Re: Reflection of properties.

You are the man. I haven't tested it, but the code makes sense.

Jon Davis wrote:[color=blue]
> (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" <nospam@nospam.com> wrote in message
> news:ex1VtGoTDHA.2128@TK2MSFTNGP12.phx.gbl...
>[color=green]
>>Jon Davis wrote:
>>[color=darkred]
>>>PropertyInfo objects contain a method called GetValue(...) in which you[/color][/color]
>
> pass
>[color=green][color=darkred]
>>>the object instance.[/color]
>>
>>I am not familiar with that object. Could you provide an example and/or
>> how to loop through all the properties?
>>
>>[color=darkred]
>>>Jon
>>>
>>>"Frank Rizzo" <nospam@nospam.com> wrote in message
>>>news:%23B5zhqnTDHA.2228@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
>>>>
>>>>
>>>
>>>
>>>[/color][/color]
>
>[/color]

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.