473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

getting values from reflection ( repost )

I am sorry, I am not able to get the reply window open and I had the flu.
The error I get is the Object does not match target type

FTE_PathManager.PathClass vbPATH = new FTE_PathManager.PathClass();
Type tt= vbPATH.GetType();
PropertyInfo[] ppInfo = tt.GetProperties() ;
foreach(PropertyInfo p in ppInfo)
{
if (p.GetIndexParameters().Length==0)
{ Console.WriteLine(p.ToString());
// throws an excpetion
object pObj = new object();
property_value = p.GetValue(pObj,null);

// what should I pass into p.GetValue ??

--
Andrew
Nov 16 '05 #1
3 4468
andrewcw <an******@acw.com> wrote:
I am sorry, I am not able to get the reply window open and I had the flu.
The error I get is the Object does not match target type

FTE_PathManager.PathClass vbPATH = new FTE_PathManager.PathClass();
Type tt= vbPATH.GetType();
PropertyInfo[] ppInfo = tt.GetProperties() ;
foreach(PropertyInfo p in ppInfo)
{
if (p.GetIndexParameters().Length==0)
{ Console.WriteLine(p.ToString());
// throws an excpetion
object pObj = new object();
property_value = p.GetValue(pObj,null);

// what should I pass into p.GetValue ??


The instance of PathClass you want to retrieve values from.

Note that to just get the Type associated with a type, you can use
typeof(...) instead of creating an instance and then calling GetType.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Thanks Jom,

It strikes me as odd that I would re-reference the object as
p.GetValue(vbPATH) when p is also from the same object,
but it did work. Thanks again !

"andrewcw" wrote:
I am sorry, I am not able to get the reply window open and I had the flu.
The error I get is the Object does not match target type

FTE_PathManager.PathClass vbPATH = new FTE_PathManager.PathClass();
Type tt= vbPATH.GetType();
PropertyInfo[] ppInfo = tt.GetProperties() ;
foreach(PropertyInfo p in ppInfo)
{
if (p.GetIndexParameters().Length==0)
{ Console.WriteLine(p.ToString());
// throws an excpetion
object pObj = new object();
property_value = p.GetValue(pObj,null);

// what should I pass into p.GetValue ??

--
Andrew

Nov 16 '05 #3
The issue is you might not have got hold of the type instance from the object itself - you might, for example, have used the typeof operator. The Type instance is simply a view on to that *classes* type information, its not associated with any instance of that class. So when you invoke functionality late bound you have to tell it what instance you'd like it to act upon.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

Thanks Jom,

It strikes me as odd that I would re-reference the object as
p.GetValue(vbPATH) when p is also from the same object,
but it did work. Thanks again !
Nov 16 '05 #4

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

Similar topics

2
by: Marcin | last post by:
Hello! Is there any method to detect parameters values passed to called method? For example: public Guid ApplicationLogin(string userName, string password, int dbId)
7
by: Brad Quinn | last post by:
Is there a way to get the values of the paramaters to a method programatically? I know that I can use reflection to find out the parameter names and types, etc., but I want to know the values...
2
by: andrewcw | last post by:
I have a snippet of code that feeds a tree view, the properties show up BUT if I try and obtain the values of the property the code throws an error. // throws an excpetion //property_value =...
6
by: Ken Varn | last post by:
I have an ASP.NET application that is calling a custom class that is trying to parse all of the members of my Page object using Type.GetMembers(). The problem that I am having is that private...
5
by: Erol | last post by:
How do I get a type from a string? I'm retrieving a string value from my database so that I can set my property values dynamically. In the event "Form1_Load", you will see that I'm trying to set...
2
by: Prabhudhas Peter | last post by:
Hello, Need an easy way to Display the property values of an object (dynamically) ie I need to show the values of an Object in a rich text box. Background : We have a form, with a rich...
20
by: Shawnk | last post by:
I would like to get the class INSTANCE name (not type name) of an 'object'. I can get the object (l_obj_ref.GetType()) and then get the (l_obj_typ.Name) for the class name. I there any way of...
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
0
by: mike1402 | last post by:
Hi ! I get the error below sometimes when retrieving a big amount of data using Datadapter.Fill(dataset,"table"). But when I send the command Fill again, there is no error. Is it a fault of...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.