Activate object from ParameterType value.

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
neudealAsked:
Who is Participating?
 
ripahoratiuCommented:
// 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
 
ripahoratiuCommented:
*sry, replace all ParameterType with some specific type of the parameter (i.e. String, MyClass, etc.)
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.