473,804 Members | 4,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tip: Propertyinfo.ge tValue in VB

I had a problem using system.reflecti on.propertyinfo .getvalue in vb -
and searched a lots of newsgroups and libraries - but none had the
solution to my problem - and it also seamed like many others had the
same problem: system.reflecti on.propertyinfo .getValue fails with
"Object does not match target type."

As many of the posts where to old to answer, here's the "solution" :
The obj parameter is the object from where propertyinfo gets the
property from - not the property object it self..

To list all values of all properties of type system.string - ex:

Dim str as string ="" ' - some string to send the output to
Dim obj as someobject ' - a object with properties
Dim objProps() As System.Reflecti on.PropertyInfo =
GetType(obj).Ge tProperties

For Each p As System.Reflecti on.PropertyInfo In objProps
If p.PropertyType Is GetType(System. String) Then
str += p.Name.ToString & " = " & p.GetValue(obj,
Nothing).ToStri ng
end if
next

Apr 21 '06 #1
0 7186

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

Similar topics

1
7409
by: gt | last post by:
I am trying to replicate the functionality of DataTextField/DataValueFields in an extended DropDownList control that I have created in order to provide a third value for each ListItem. This value will be stored in a client-side array currently as that is where it is required. Now to the problem. I've overriden the DataBind Method of my DropDownList and within it have added the code below: Type DataSourceType =...
3
1992
by: Oskar Lundgren | last post by:
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):
15
8244
by: Charles Law | last post by:
I have adapted the following code from the MSDN help for PropertyInfo SetValue. In the original code, the structure MyStructure is defined as a class MyProperty, and it works as expected. There is also a minor change in class Mypropertyinfo, which I have commented out. When using a structure, however, the second call to GetValue returns "Default caption". Can anyone tell me why, and how I can make this work? <code> Imports System
0
417
by: Paul | last post by:
I'd like to iterate through the controls on pages within a dll. I can get a page's Controls in a PropertyInfo class but can't extract the ControlsCollection from there. Dim asm As = asm.GetExecutingAssembly Dim oType As Type For Each oType In asm.GetTypes If oType.BaseType.ToString() = "System.Web.UI.Page" Then
1
5953
by: INeedADip | last post by:
PropertyInfo props = obj.GetType().GetProperties(); foreach (PropertyInfo p in props) if (p.PropertyType is ValueType) this._commonProperties.Add(p.Name, p.GetValue(request, null).ToString()); I get a warning that says p.PropertyType will never be ValueType....and it was right. After stepping through it the types are "System.Boolean" etc... I want to add all integer, string, and boolean types to NameValueCollection,
2
2522
by: Carlos Rodriguez | last post by:
I have the following function in C#public void Undo(IDesignerHost host) { if (!this.componentName.Equals(string.Empty) && (this.member != null)) { IContainer container1 = (IContainer) host.GetService(typeof(IContainer)); IComponent component1 = container1.Components; PropertyInfo info1 = component1.GetType().GetProperty(this.member.Name);
7
16574
by: Tom Dacon | last post by:
I'm using Reflection to iterate over the properties and fields of an arbitrary object. For non-indexed properties it's pi.GetValue(theObject, Nothing) for VB, or pi.GetValue(theObject, null) for C# For indexed properties, instead of Nothing (null) you pass an array of index values. OK, no problem so far.
1
3599
by: samueltilden | last post by:
I am writing a very generic DumpObject(object Obj) method. I can easily GetType() and GetType().GetProperties(). I can easily PropertyInfo.GetValue(Obj, null) for scalar variables. The problem is arrays or collections which require this syntax: PropertyInfo.GetValue(Object, Object index)
1
4872
by: damiensawyer | last post by:
Hi, I need to invoke .getvalue and .setvalue on fieldinfo and propetyinfo objects. Even though they're both derived from MemberInfo, they don't share those two methods. I've finding myself writing the following types of structure over and over. Is there something I'm missing? Or some 'funky' 3.5 delegate/lambda expression way of doing this? Thanks very much in advance,
0
9710
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9589
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10593
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10329
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,...
1
7626
isladogs
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...
0
5527
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...
1
4304
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
2
3830
muto222
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.