473,324 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Retrieving properties dynamically

balabaster
797 Expert 512MB
Okay, I need some inspiration to get me started on the implementation of an idea I've got. I want to specify in the config file of my .NET app that will give me a reference to a property on one of my objects in my application.

For instance:

<predefinedVariables>
<add name="[#SALETOTAL#]" displayText="Sale total amount" property="Bill.Total">
<add name="[#DELADDR#]" displayText="Customer's delivery address" property="Customer.Address">
</predefinedVariables>

Obviously the Bill.Total refers to the property "Total" within the "Bill" instance that is passed into the evaluation module. Likewise, the Customer.Address refers to the "Address" property of the instance of "Customer" that is passed into the evaluation module.

This mechanism will allow the user to attach predefined variable values to equations. I thought about using the same dynamic compilation method that I used for my expression evaluator to grab the value using the CodeDom, but I wondered if there wasn't an simpler or typesafe method. I know about creating custom configuration section handlers and wonder if I couldn't use some similar mechanism that .NET uses to attach the config handler to the config file in order to do that. That way I might be able to make use of intellisense which would be much more advantageous for code maintenance for future developers.
Sep 15 '08 #1
4 1368
Frinavale
9,735 Expert Mod 8TB
You're going to have to use the System.Reflection Namespace.
There's a GetProperties method that lets you retrieve the object's properties

Expand|Select|Wrap|Line Numbers
  1. Dim theObjectType As Type
  2. theObjectType  = GetType(MyDynamicObject)
  3.  
  4. Dim listOfPropertyInfos() As PropertyInfo = theObjectType  .GetProperties
  5.  
  6. For Each p As PropertyInfo In listOfPropertyInfos
  7.      Dim myString As String = p.Name
  8. Next
  9.  
Check the name against what you're storing in your config file and determine if that's what you want to call. There's also a GetMethods method too. I think the Reflection Namespace is what you're going to want to look into.

Cheers!

-Frinny
Sep 17 '08 #2
balabaster
797 Expert 512MB
You're going to have to use the System.Reflection Namespace.
There's a GetProperties method that lets you retrieve the object's properties

Expand|Select|Wrap|Line Numbers
  1. Dim theObjectType As Type
  2. theObjectType  = GetType(MyDynamicObject)
  3.  
  4. Dim listOfPropertyInfos() As PropertyInfo = theObjectType  .GetProperties
  5.  
  6. For Each p As PropertyInfo In listOfPropertyInfos
  7.      Dim myString As String = p.Name
  8. Next
  9.  
Check the name against what you're storing in your config file and determine if that's what you want to call. There's also a GetMethods method too. I think the Reflection Namespace is what you're going to want to look into.

Cheers!

-Frinny
Thanks, I figured this was going to be the best approach. I was just hoping there was something more... implicit(?). No worries, I'm working on it now - I'll let you know how I fare.
Sep 17 '08 #3
Frinavale
9,735 Expert Mod 8TB
Thanks, I figured this was going to be the best approach. I was just hoping there was something more... implicit(?). No worries, I'm working on it now - I'll let you know how I fare.
Good Luck :)


-Frinny
Sep 17 '08 #4
balabaster
797 Expert 512MB
Good Luck :)


-Frinny
Thanks... I'll yell if I have any questions :oP
Sep 17 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Klaas Seelen | last post by:
Hi, On a webpage I have three comboboxes. The second and the third are dynamically filled dependent from the choice in the first combobox. Each choice in all three boxes consist of a numeric...
4
by: Lan Vuong | last post by:
Hi everyone, I'm trying to retrieve the width of a cell as the table is being dynamically created and add it to a total. I can get the width from an eventhandler such as: <td...
0
by: Balamurukan | last post by:
hai, PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this); PropertyDescriptor myProperty = properties.Find ("Cols",false); PropertyDescriptorCollection arr=...
3
by: Dotnet Gruven | last post by:
I've built a WebForm with a Table added dynamically in Page_Load when IsPostBack is false. The table includes a couple of TextBoxes, RadioButtonLists and CheckboxLists. On postback, those...
0
by: Andy | last post by:
Hi All. I'm working for a company that has set out a guideline for retrieving data from a database. Nobody can explain to me the reason for the following. When retrieving a set of records...
3
by: Dan | last post by:
Is it possible to dynamically create and populate properties? Below is my class. I would like to define properties for each of the items in my two arrays without actually defining each one. (There...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
0
by: pvishweshwar | last post by:
Hi All, am developing one application in which i have to retrieve the msolap dimension members properties data.In this till now am able to get the member values properly.But the problem is am...
5
by: Nathan Sokalski | last post by:
I have a custom control that I wrote (I inherit from System.Web.UI.WebControls.CompositeControl). I dynamically add this control to my Page, but I was told that dynamically added controls do not...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.