Solved

GetValue/SetValue with Public Properties using Reflection on a class

Posted on 2011-09-21
1
258 Views
Last Modified: 2012-05-12
Experts,

I have a class: clsProp_ProjectStructure.subCls_ProjectStructureDataSourceLink.  This class has the following Public Properties:

StrVarDataSourceLink.p_sDateAdded
StrVarDataSourceLink.p_sDateModified
StrVarDataSourceLink.p_iCodeSequence
StrVarDataSourceLink.p_sRecordStatus
StrVarDataSourceLink.p_sDataSourceName
StrVarDataSourceLink.p_iDatabaseType
StrVarDataSourceLink.p_bLockProperties
StrVarDataSourceLink.p_sConnectionMethod
StrVarDataSourceLink.p_sConnectionType
StrVarDataSourceLink.p_sServerName
StrVarDataSourceLink.p_sServerInstance
StrVarDataSourceLink.p_sDatabaseFolder
StrVarDataSourceLink.p_sDatabaseName
StrVarDataSourceLink.p_sTableName

Each of the properties has "_p" followed vy a letter then the actual variable.  

s is for String
i is for Integer
b is for Boolean

I want to store the value of the Public Property in a DataTable.  This table has three columns; PropertyName, PropertyVariable, and PropertyValue.  I store the DataTable in a DataSet called dsDataSet.  The DataTable is called Properties with the three columns just mentioned.    I have gotten both the PropertyName and PropertyVariable, but am having issues getting the PropertyValue with GetValue.

I know that I use reflection to browse the properties.  I also know. That Type is used as well.  My issue is the proper coding in VB to get the value of the Public Property.  GetProperties allows me to get multiple pieces of info on each Property, but I can't seam to figure out how to return the value.  I would also like to use SetValue.

Could you show me an exqmple using the following asumptions:

1. The DataSet I am building is generated from one call to a class: clsDataSourceLinkBuilder_DataSet
2. The DataSet name is: dsDataSet
3. The TableName is: Properties
4. Each propooperty is as shown above
5. The class loops through the properties
6. pType would be the Class/Form/Control, etc. Iten that contains the properties I want to review.
7. pValue would be the object I am returning that holds the value
8. pInfo would be the PropertyInfo I am defining

pValue = PropertyInfo() = GetType(pType).GetProperties

Would I use pInfo.GetType(pValue) as well?  I know thqt GetValue(pValue, Nothing) must match the type of the variable I am currently looking at in the loop.  

For iLoop as Integer = 0 to pInfo.Length - 1
...
...
Next iLoop

Thanks very much for the assistance.
0
Comment
Question by:Peter Allen
1 Comment
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 250 total points
ID: 36576232
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now