Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Activate object from ParameterType value.

Posted on 2007-10-16
4
Medium Priority
?
154 Views
Last Modified: 2010-04-15
Hello,

I need to instantiate an object of type someParameterInfo.ParameterType.

Basically,  I want to reconstitute the parameter type of a method by calling something like this:

ParameterType p = some parameterType;

Type t = Type.GetType(p.FullName); // does not work
object obj = Activator.CreateInstance(t);

Where t is type System.Int32 or the like.  I would think that p.FullName would give me "System.Int32" but it does not.

Any suggestions?

Thanks,
Robert
0
Comment
Question by:neudeal
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
ripahoratiu earned 2000 total points
ID: 20091219
// if you have an instance of ParameterType
object p = new ParameterType(); // p is declared an object so it can by any creatable object
Type t = p.GetType;  
object obj = Activator.CreateInstance(t);

//if you don't have an instance but know the type
object obj = Activator.CreateInstance(typeof(ParameterType ));



0
 
LVL 9

Expert Comment

by:ripahoratiu
ID: 20091241
*sry, replace all ParameterType with some specific type of the parameter (i.e. String, MyClass, etc.)
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20294957
Forced accept.

Computer101
EE Admin
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question