dynamically address class vairables [modified]
-
Is there a way to convert a string type into a variable type: "string" > this."string"? The effect I am looking for would be like the dynamic at runtime statement"this.'string' = 'the strings value'" sets a vaulue for the static compile time value "this.stringName" Any comments or help? Class MyClass { private string cn; private string sn; ///I know.....not correct syntax string this.cn = cn; string this.sn = sn; public void GetADObjectInfo(string dn) { DirectoryEntry entry = new DirectoryEntry("LDAP://"+ dn); foreach (string strAttrName in entry.Properties.PropertyNames) { try { this.cn = (string)result.Properties[cn][0]; //I want the above to become something like this //this.strAttrName = (string)result.Properties[strAttName][0]; } catch { } } } } with Regards, shwa guy -- modified at 12:18 Friday 23rd November, 2007
-
Is there a way to convert a string type into a variable type: "string" > this."string"? The effect I am looking for would be like the dynamic at runtime statement"this.'string' = 'the strings value'" sets a vaulue for the static compile time value "this.stringName" Any comments or help? Class MyClass { private string cn; private string sn; ///I know.....not correct syntax string this.cn = cn; string this.sn = sn; public void GetADObjectInfo(string dn) { DirectoryEntry entry = new DirectoryEntry("LDAP://"+ dn); foreach (string strAttrName in entry.Properties.PropertyNames) { try { this.cn = (string)result.Properties[cn][0]; //I want the above to become something like this //this.strAttrName = (string)result.Properties[strAttName][0]; } catch { } } } } with Regards, shwa guy -- modified at 12:18 Friday 23rd November, 2007
shwaguy wrote:
Is there a way to convert a string type into a variable type: "string" > this."string"?
??? :confused: huh? Can you rephrase your question?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook "There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib "Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
-
Is there a way to convert a string type into a variable type: "string" > this."string"? The effect I am looking for would be like the dynamic at runtime statement"this.'string' = 'the strings value'" sets a vaulue for the static compile time value "this.stringName" Any comments or help? Class MyClass { private string cn; private string sn; ///I know.....not correct syntax string this.cn = cn; string this.sn = sn; public void GetADObjectInfo(string dn) { DirectoryEntry entry = new DirectoryEntry("LDAP://"+ dn); foreach (string strAttrName in entry.Properties.PropertyNames) { try { this.cn = (string)result.Properties[cn][0]; //I want the above to become something like this //this.strAttrName = (string)result.Properties[strAttName][0]; } catch { } } } } with Regards, shwa guy -- modified at 12:18 Friday 23rd November, 2007
have a look at the System.Reflection namespace. There are several articles about reflection here on CP. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
-
have a look at the System.Reflection namespace. There are several articles about reflection here on CP. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
you actually understood what was meant? what was it?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook "There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib "Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
-
you actually understood what was meant? what was it?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook "There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib "Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
the question was: "If I have the name of an existing field/method/property in a string, how can I access that particular field/method/property?" or something completely different. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
-
the question was: "If I have the name of an existing field/method/property in a string, how can I access that particular field/method/property?" or something completely different. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
ah! Well, I'm glad you were able to understand what was wanted, because I sure didn't! :laugh:
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook "There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib "Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"