473,320 Members | 1,722 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,320 software developers and data experts.

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

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
8 1295
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
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
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
> 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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark | last post by:
Hi all, i'm trying to serialize a class. Using the constructor of XmlSerializer i get these (odd?) errors: "File or assembly name goseij9w.dll, or one of its dependencies, was not found"....
2
by: Ryan Mitchley | last post by:
Hi all I have code for an object factory, heavily based on an article by Jim Hyslop (although I've made minor modifications). The factory was working fine using g++, but since switching to the...
1
by: Patrick Stinson | last post by:
I am trying to create a way to register static members of a **class**, not an object, for making an object factory. The main thing I want is to be able to make a call like class MyClass {...
6
by: TZ | last post by:
I have two classes, UIHousehold and WIZEditHousehold (both are winforms). UIHousehold creates and shows the WIZEditHousehold (WIZEditHousehold can't be modal, so UIHousehold doesn't know when...
15
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
2
by: John Mullin | last post by:
We are having a problem which appears similar to a previous posting: http://groups.google.com/groups?hl=en&lr=&frame=right&th=d97f552e10f8c94c&seekm=OZw33z9EDHA.2312%40TK2MSFTNGP10.phx.gbl#link1 ...
0
by: a | last post by:
I need to create an instance of a custom object 'School.Teacher' and use it in a Profile object. I'm developing a bad case of "Pretzel Logic" thinking about this. Filling the custom object ...
7
by: Steve | last post by:
I am building an object library for tables in a database. What is the best practice for creating objects like this? For example, say I have the following tables in my database: User: - Id -...
11
by: Andrus | last post by:
I'm implementing entity object which should populate its properties from database when property is first referenced. In RDL reports I use object properties like MyObject.MyProperty MyObject...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
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: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.