954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to pass a Type?

I think it's more difficult to ask than answering the question.
I wanna ask my question with an example:
You know that we can bind an object to a DataSource, and that object could be of any type. So suppose I've bound an object of type "MyClass" to DataSource of a DataSet.
Now I send this dataset as a parameter to another class in another DLL, and in this DLL file I want to create a List<> of type of "MyClass".
As I have not access to "MyClass" type i can use this code to get the type of DataSource:

_dataSet.DataSource.GetType()

but I can't use the code like the following to create a List of type of "MyClass":
List<_dataSet.DataSource.GetType()> _list;

What should I do in this situation?

Gabrielsoroush
Newbie Poster
1 post since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

You can get the type of an object by passing that object to they typeof method.

Type t = typeof(MyClass);


but if the type is not available to the namespace you are in, then it won't work. you need to expose that type to your other dll, and if you can't, then you need to define that type again so that it is available.

Diamonddrake
Master Poster
724 posts since Mar 2008
Reputation Points: 442
Solved Threads: 89
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: