Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

GetValue/SetValue with Public Properties using Reflection on a class

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
Peter Allen
Asked:
Peter Allen
1 Solution
 
Bob LearnedCommented:
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
 
dj_alikCommented:
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now