Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass class name string to class

Status
Not open for further replies.

hacesol

Programmer
Apr 2, 2007
10
ES
Hi:

How can I pass to the class below, the name of the class type in order to assume the string type passed, in the class methods:

For example

I have the following classes:

---------------

public class Class1 : System.Collections.CollectionBase
{
public Class1(string class_type_str)
{

}
public "class_type_str" this[int index]
{
get
{
//** Retorna valor
return ("class_type_str")this.List[index];
}
set
{
//** Almacena valor
this.List[index] = value;
}
}

public void Add("class_type_str" source)
{
this.List.Add(source);
}

}



public class Class2
{
public string Code;
public string Name;
}

public class Class3
{
public string Code;
public string Name1;
public string Name2;
}



----------------



I would like to do something like this:

Class1 obj = new Class1("Class2"); or Class1 obj = new Class1("Class3");

and the Indexers and the Add method use instance of Class2 or Class3.

Thanks


 
why not use a generic class?

You can declare the Class1 as a generic class, inside the class you can delcare an object declared as the generic type and then use that object to initiate the method.

i dont immediately have an example with me.

Try this link:


Known is handfull, Unknown is worldfull
 
Thanks to everyone but the System.Collections.Generic is only for ASP.NET 2.0 and I´m using Framework 1.1

Is there another solution?

Thanks
 
why not use an interface?

make all your classes implement the same. In your control class you can have the property as the interface???

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top