String to Object Question
-
Hello all! If an object has a member, who's name was not known but only stored in a string, how could I access that member? Thanks in advance, Fahad Sadah
New freeware site underway!
-
Hello all! If an object has a member, who's name was not known but only stored in a string, how could I access that member? Thanks in advance, Fahad Sadah
New freeware site underway!
What you exactly mean by this question??? How come an object has a member who has no name ! and if it is then what you think intelliSense is for? and didn't understand yet what you exactly trying to ask.
AliAmjad(MCP) First make it Run THEN make it Run Fast!
-
Hello all! If an object has a member, who's name was not known but only stored in a string, how could I access that member? Thanks in advance, Fahad Sadah
New freeware site underway!
-
What you exactly mean by this question??? How come an object has a member who has no name ! and if it is then what you think intelliSense is for? and didn't understand yet what you exactly trying to ask.
AliAmjad(MCP) First make it Run THEN make it Run Fast!
AliAmjad wrote:
How come an object has a member who has no name !
He didn't say the object's member had no name. He said the name was stored in a string.
Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website
-
AliAmjad wrote:
How come an object has a member who has no name !
He didn't say the object's member had no name. He said the name was stored in a string.
Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website
-
Thanks for correcting me man ! but can you please explain it a bit "object has a member, who's name was not known but only stored in a string" I still don't get it.
AliAmjad(MCP) First make it Run THEN make it Run Fast!
I'll give an example:
Dim obj As New MyClass Dim str As String = "member"
Assume that str was user input, and I do not know what it is. How do I access obj.str? -
Pardon the noobish question please: whats reflection?
-
I'll give an example:
Dim obj As New MyClass Dim str As String = "member"
Assume that str was user input, and I do not know what it is. How do I access obj.str?Are you saying that user knew the method in your Class and you want to choose the method in your MyClass according to what user enters ???
Fahad Sadah wrote:
How do I access obj.str?
str is not even a member of MyClass its just a string field which can be used at class level or in a method locally depends on its declaration.
AliAmjad(MCP) First make it Run THEN make it Run Fast!
-
Are you saying that user knew the method in your Class and you want to choose the method in your MyClass according to what user enters ???
Fahad Sadah wrote:
How do I access obj.str?
str is not even a member of MyClass its just a string field which can be used at class level or in a method locally depends on its declaration.
AliAmjad(MCP) First make it Run THEN make it Run Fast!
AliAmjad wrote:
Are you saying that user knew the method in your Class and you want to choose the method in your MyClass according to what user enters ???
Or maybe the user knows something from which a lookup in a database or XML file could be made which returns the name of the method.
AliAmjad wrote:
str is not even a member of MyClass
True, you cannot use a string in that way. But you can use the string to invoke the correct method through "Reflection"
Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website
-
Pardon the noobish question please: whats reflection?
Fahad Sadah wrote:
whats reflection?
There is a System.Reflection namespace that contains a number of useful classes to help you with this. Everything has a
GetType()
method which returns aType
object. UseGetMethod()
to find the method that you want with the string. This will return aMethodInfo
object. You can then use theMethodInfo
object with your object toInvoke()
the method.
Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website
-
AliAmjad wrote:
Are you saying that user knew the method in your Class and you want to choose the method in your MyClass according to what user enters ???
Or maybe the user knows something from which a lookup in a database or XML file could be made which returns the name of the method.
AliAmjad wrote:
str is not even a member of MyClass
True, you cannot use a string in that way. But you can use the string to invoke the correct method through "Reflection"
Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website
-
I know buddy but as he said in his later post bellow that he's a newbie didn't know anything about reflection so thought that he didn't ask a question related to reflection !
AliAmjad(MCP) First make it Run THEN make it Run Fast!
AliAmjad wrote:
I know buddy but as he said in his later post bellow that he's a newbie didn't know anything about reflection so thought that he didn't ask a question related to reflection !
Why would you think that? The most obvious thing is that if he didn't know anything about reflection then his question may be related but he didn't realise it was related. It is therefore necessary to bring the idea to his attention to find out if it really is related or not.
Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website
-
AliAmjad wrote:
I know buddy but as he said in his later post bellow that he's a newbie didn't know anything about reflection so thought that he didn't ask a question related to reflection !
Why would you think that? The most obvious thing is that if he didn't know anything about reflection then his question may be related but he didn't realise it was related. It is therefore necessary to bring the idea to his attention to find out if it really is related or not.
Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website