Solved

GetValue/SetValue with Public Properties using Reflection on a class

Posted on 2011-09-21
2
294 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()
0
Comment
Question by:Peter Allen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 36577902
You should be able to use LINQ to DataSet extensions, to write a LINQ query to convert a generics list of that class into a DataTable.
0
 
LVL 18

Accepted Solution

by:
dj_alik earned 250 total points
ID: 36578210
Convert Generic List In To DataTable
http://amitpatriwala.wordpress.com/2008/12/03/convert-generic-list-in-to-datatable/

Casting from a Collection to a Data Table using Generics and Attributes
http://www.codeproject.com/KB/cs/coreweb01.aspx

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

732 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