By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,202 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,202 IT Pros & Developers. It's quick & easy.

How can i get a object by it name in the class whict create it.

P: n/a
for example,i create a class as below

public class testClass{
private object obj //this is the right object i need
public testClass(){
obj = new object();
}
public object GetObj(string name){
return this.XXXXX(name);// now how can i get the object with the
name
}
}

thanks for ur help.

eugene, china
2006-5-18
May 18 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Use the system.Reflection namespce, specifically, the PropertyInfo class.
For details, see:

http://msdn2.microsoft.com/en-us/lib...pertyinfo.aspx

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

The man who questions opinions is wise.
The man who quarrels with facts is a fool.
"@@Worker" <中国人@中华人民共和国.中国> wrote in message
news:eA**************@TK2MSFTNGP04.phx.gbl...
for example,i create a class as below

public class testClass{
private object obj //this is the right object i need
public testClass(){
obj = new object();
}
public object GetObj(string name){
return this.XXXXX(name);// now how can i get the object with the
name
}
}

thanks for ur help.

eugene, china
2006-5-18

May 18 '06 #2

P: n/a
It looks like you are asking for .NET Reflection, but what exactly is
this.XXXXXX. Can you please elaborate a bit.
--

Stoitcho Goutsev (100)
"@@Worker" <中国人@中华人民共和国.中国> wrote in message
news:eA**************@TK2MSFTNGP04.phx.gbl...
for example,i create a class as below

public class testClass{
private object obj //this is the right object i need
public testClass(){
obj = new object();
}
public object GetObj(string name){
return this.XXXXX(name);// now how can i get the object with the
name
}
}

thanks for ur help.

eugene, china
2006-5-18

May 18 '06 #3

P: n/a
public class testClass{
private object obj1;
private object obj2;
private Hashtable ht;
public testClass()
{
obj1 = new object();
obj2 = new object();
ht = new Hashtable();
ht["obj1"] = obj1;
ht["obj2"] = obj2;
}
public object GetObj(string name)
{
return ht[name]
}
}

May 18 '06 #4

P: n/a
> public class testClass{
private object obj //this is the right object i need
public testClass(){
obj = new object();
}
public object GetObj(string name){
switch ( name )
{
case "obj" : return ( this.obj ) ;
..
..
..
default : throw ...
}
}
}


May 18 '06 #5

P: n/a
because i do not know how to get the object, one of the its function may did
it.
"Stoitcho Goutsev (100)" <10*@100.com> 写入消息新闻:%2****************@TK2MSFTNGP03.phx.g bl...
It looks like you are asking for .NET Reflection, but what exactly is
this.XXXXXX. Can you please elaborate a bit.
--

Stoitcho Goutsev (100)
"@@Worker" <中国人@中华人民共和国.中国> wrote in message
news:eA**************@TK2MSFTNGP04.phx.gbl...
for example,i create a class as below

public class testClass{
private object obj //this is the right object i need
public testClass(){
obj = new object();
}
public object GetObj(string name){
return this.XXXXX(name);// now how can i get the object with the
name
}
}

thanks for ur help.

eugene, china
2006-5-18


May 19 '06 #6

P: n/a
it's not the right way i want
but thanks all the same.
<ja**********@gmail.com>
??????:11**********************@u72g2000cwu.google groups.com...
public class testClass{
private object obj1;
private object obj2;
private Hashtable ht;
public testClass()
{
obj1 = new object();
obj2 = new object();
ht = new Hashtable();
ht["obj1"] = obj1;
ht["obj2"] = obj2;
}
public object GetObj(string name)
{
return ht[name]
}
}

May 19 '06 #7

P: n/a
it's not the right way i want
but thanks all the same.
"PIEBALD" <PI*****@discussions.microsoft.com> 写入消息新闻:93**********************************@ microsoft.com...
public class testClass{
private object obj //this is the right object i need
public testClass(){
obj = new object();
}
public object GetObj(string name){


switch ( name )
{
case "obj" : return ( this.obj ) ;
.
.
.
default : throw ...
}
}
}

May 19 '06 #8

P: n/a
can you write a sample here?

thanks

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> 写入消息新闻:%2****************@TK2MSFTNGP02.phx.g bl...
Use the system.Reflection namespce, specifically, the PropertyInfo class.
For details, see:

http://msdn2.microsoft.com/en-us/lib...pertyinfo.aspx

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

The man who questions opinions is wise.
The man who quarrels with facts is a fool.
"@@Worker" <中国人@中华人民共和国.中国> wrote in message
news:eA**************@TK2MSFTNGP04.phx.gbl...
for example,i create a class as below

public class testClass{
private object obj //this is the right object i need
public testClass(){
obj = new object();
}
public object GetObj(string name){
return this.XXXXX(name);// now how can i get the object with the
name
}
}

thanks for ur help.

eugene, china
2006-5-18


May 19 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.