Solved

GetValue/SetValue with Public Properties using Reflection on a class

Posted on 2011-09-21
2
283 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

11 Experts available now in Live!

Get 1:1 Help Now