473,396 Members | 2,029 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.

Reflection and PropertyInfo

I want to iterate over fields declared like this, using reflection
(and there are good reasons for that):

Protected WithEvents Foo1 As Bar
Protected WithEvents Foo2 As Bar
....

I use the following code to get an array containing the fields
(wrapped in PropertyInfo objects):

Dim objs As Object() =
Me.GetType().GetProperties(Reflection.BindingFlags .Instance Or
Reflection.BindingFlags.NonPublic)

My question is: How do I get the wrapped "Bar" objects (Foo1, Foo2 and
so on)out of the PropertyInfo objects, so I can make calls to the
methods of the "Bar" objects. Using GetValue on the PropertyInfo
objects does not work.
Nov 20 '05 #1
3 1971
Oskar,
Using GetValue on the PropertyInfo
objects does not work.


No? How does it fail?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #2
Hello Oskar
See the following example its for MenuItem

<code>
Dim myForm As Type = f.GetType()

Dim fields As FieldInfo() = myForm.GetFields
(BindingFlags.Instance Or BindingFlags.NonPublic)

For Each field As FieldInfo In fields

If field.FieldType.Name = "MenuItem" Then
Dim menu As MenuItem = DirectCast(field.GetValue
(f), MenuItem)
'' you can use it here.
end if
next
</code>

Kind Regards
Jorge
-----Original Message-----
I want to iterate over fields declared like this, using reflection(and there are good reasons for that):

Protected WithEvents Foo1 As Bar
Protected WithEvents Foo2 As Bar
....

I use the following code to get an array containing the fields(wrapped in PropertyInfo objects):

Dim objs As Object() =
Me.GetType().GetProperties (Reflection.BindingFlags.Instance OrReflection.BindingFlags.NonPublic)

My question is: How do I get the wrapped "Bar" objects (Foo1, Foo2 andso on)out of the PropertyInfo objects, so I can make calls to themethods of the "Bar" objects. Using GetValue on the PropertyInfoobjects does not work.
.

Nov 20 '05 #3
The error message I get (at runtime):

Property Get method was not found

This does sound reasonable to me, since I haven't declared such a
method...

Anyway, I have found a solution of my problem. I didn't need to use
reflection, since the Bar class is a subclass System.Web.UI.WebControl
and these objects easily can be retrieved using the Controls collection.
And, yes, I'm new to Visual Basic .NET...

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #4

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

Similar topics

0
by: Nigel Sampson | last post by:
ey all, I'm in the process of creating a method of tracking whenever an objects properties are changed. Since its not possible to alter existing types I decided to used a proxy generated using...
6
by: Lars Nielsen | last post by:
Hi everybody, I've run into a problem when using the reflection assembly on COM objects and been browsing around the net for some while. Apparently a few has asked the same question though no...
4
by: Frank Rizzo | last post by:
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...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
3
by: Roger Webb | last post by:
Hey, I'm attempting to use reflection in order to get the types of properties in a class. However, I seem to be having trouble determining exactly which type I am getting. In the foreach of...
2
by: Marc | last post by:
Given a class 'Invoice' with a property 'public IMyColl<IInvoiceLine> InvoiceLines' where 'IMyColl<T> : IList<T>' i would like to detect by reflection that 'InvoiceLines' is a...
11
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
4
by: Lucas Tam | last post by:
Hi all, I need to set a property on a subclass such as: Report.ExportOptions.ExportFormatType = ExportFormatType.Excel AND Report.ExportOptions.FormatOptions = excelFormatOpts
15
by: satankidneypie | last post by:
Hi, I'm going to start this off with some code as it'll make it easier to explain afterwards... using System; namespace ConsoleApplication1 { /// <summary>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.