472,110 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,110 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 1923
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Nigel Sampson | last post: by
6 posts views Thread by Lars Nielsen | last post: by
4 posts views Thread by Frank Rizzo | last post: by
3 posts views Thread by Roger Webb | last post: by
2 posts views Thread by Marc | last post: by
15 posts views Thread by satankidneypie | last post: by

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.