473,890 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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().Ge tProperties(Ref lection.Binding Flags.Instance Or
Reflection.Bind ingFlags.NonPub lic)

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 1992
Using GetValue on the PropertyInfo
objects does not work.

No? How does it fail?


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

Dim myForm As Type = f.GetType()

Dim fields As FieldInfo() = myForm.GetField s
(BindingFlags.I nstance Or BindingFlags.No nPublic)

For Each field As FieldInfo In fields

If field.FieldType .Name = "MenuItem" Then
Dim menu As MenuItem = DirectCast(fiel d.GetValue
(f), MenuItem)
'' you can use it here.
end if

Kind Regards
-----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().G etProperties (Reflection.Bin dingFlags.Insta nce OrReflection.Bin dingFlags.NonPu blic)

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

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.W ebControl
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

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 Reflection.Emit which inherits from the object needed Person p = (Person)ProxyBuilder.Construct(typeof(Person));
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 answer has ever occoured. This is what I'm trying to do: I wish to build a function that crawls any COM object (interop). I did shortly examine the serializer until I realized it's used for translation
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 properties, but a list of values for the properties. Thanks -- Frank
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 Windows.Forms.UserControl in a COM environment, i.e. I want to host that control in a COM host. So far, so good, I can host it, but I can not reach the parent COM object from the control (Parent property is null :( ). I have stopped the control in the...
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 running through the properties, the PropertyInfo.Name does cycle through all the properties, however, if you check the PropertyInfo.GetType().ToString() it is always "System.Reflection.PropertyInfo". Which technically makes sense. What doesnt...
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 'System.Collection.Generic.IList'. When performing something like: 'if (typeof(IList<>).IsAssignableFrom(propertyInfo.Type))' where 'propertyInfo' obviously refers to the 'InvoiceLines', the result is always 'false' because indeed 'IList<object>' and...
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
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
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>
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.