Click here to Skip to main content
15,899,026 members
Home / Discussions / C#
   

C#

 
AnswerRe: how to access a property / member variable at run time PinPopular
Giorgi Dalakishvili20-Nov-08 1:10
mentorGiorgi Dalakishvili20-Nov-08 1:10 
GeneralRe: how to access a property / member variable at run time Pin
here2learn20-Nov-08 1:50
here2learn20-Nov-08 1:50 
GeneralRe: how to access a property / member variable at run time Pin
Giorgi Dalakishvili20-Nov-08 1:58
mentorGiorgi Dalakishvili20-Nov-08 1:58 
GeneralRe: how to access a property / member variable at run time Pin
here2learn20-Nov-08 2:20
here2learn20-Nov-08 2:20 
GeneralRe: how to access a property / member variable at run time Pin
Giorgi Dalakishvili20-Nov-08 2:21
mentorGiorgi Dalakishvili20-Nov-08 2:21 
AnswerRe: how to access a property / member variable at run time Pin
Ashfield20-Nov-08 1:16
Ashfield20-Nov-08 1:16 
GeneralRe: how to access a property / member variable at run time Pin
here2learn20-Nov-08 1:52
here2learn20-Nov-08 1:52 
AnswerRe: how to access a property / member variable at run time Pin
Simon P Stevens20-Nov-08 1:25
Simon P Stevens20-Nov-08 1:25 
Like Giorgi has suggested, reflection is the way to do this.

I would be slightly careful with this though. Your basically allowing the data stored in the database to define what methods get called. What if someone nasty changed the database values to call a method that did something bad.

If you only have 4 different properties that you want to call dynamically, I would consider doing it with a switch statement. Just switch on the database value, and call the appropriate property. This way you are validating that the database value is something you expect.

I know your example was simplified, and your probably doing something more complex, so maybe a simple switch isn't appropriate. Just be aware that allowing methods to be dynamically called based on database values (Which could essentially be user input) you open up the risk of some kind of method name injection attack.

Simon

GeneralRe: how to access a property / member variable at run time Pin
here2learn20-Nov-08 1:56
here2learn20-Nov-08 1:56 
QuestionDetecting the Mouse Wheel on a ListView Control Pin
Darryl Borden19-Nov-08 23:34
Darryl Borden19-Nov-08 23:34 
AnswerRe: Detecting the Mouse Wheel on a ListView Control Pin
DaveyM6919-Nov-08 23:48
professionalDaveyM6919-Nov-08 23:48 
AnswerRe: Detecting the Mouse Wheel on a ListView Control Pin
Seraph_summer20-Nov-08 3:42
Seraph_summer20-Nov-08 3:42 
AnswerRe: Detecting the Mouse Wheel on a ListView Control Pin
DaveyM6920-Nov-08 4:32
professionalDaveyM6920-Nov-08 4:32 
QuestionProcessor ID Pin
Syed Shahid Hussain19-Nov-08 22:21
Syed Shahid Hussain19-Nov-08 22:21 
AnswerRe: Processor ID Pin
Samer Aburabie19-Nov-08 22:31
Samer Aburabie19-Nov-08 22:31 
AnswerRe: Processor ID Pin
#realJSOP19-Nov-08 23:40
professional#realJSOP19-Nov-08 23:40 
QuestionGetting data from database with ado.net with more conditions? Pin
Matjaz-xyz19-Nov-08 20:48
Matjaz-xyz19-Nov-08 20:48 
AnswerRe: Getting data from database with ado.net with more conditions? Pin
Ashfield19-Nov-08 21:43
Ashfield19-Nov-08 21:43 
GeneralRe: Getting data from database with ado.net with more conditions? Pin
Matjaz-xyz19-Nov-08 22:24
Matjaz-xyz19-Nov-08 22:24 
GeneralRe: Getting data from database with ado.net with more conditions? Pin
Ashfield19-Nov-08 23:46
Ashfield19-Nov-08 23:46 
QuestionStringFormat in TextBox Pin
chetanN19-Nov-08 20:45
chetanN19-Nov-08 20:45 
AnswerRe: StringFormat in TextBox Pin
Samer Aburabie19-Nov-08 22:46
Samer Aburabie19-Nov-08 22:46 
GeneralRe: StringFormat in TextBox Pin
chetanN19-Nov-08 23:07
chetanN19-Nov-08 23:07 
QuestionFind all ASCX files in a ASPX page Pin
buntynow19-Nov-08 20:21
buntynow19-Nov-08 20:21 
Questionselect max(string) Pin
Zeyad Jalil19-Nov-08 19:47
professionalZeyad Jalil19-Nov-08 19:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.