Activate object from ParameterType value.

Posted on 2007-10-16
Last Modified: 2010-04-15

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?

Question by:neudeal
    LVL 9

    Accepted Solution

    // 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 ));

    LVL 9

    Expert Comment

    *sry, replace all ParameterType with some specific type of the parameter (i.e. String, MyClass, etc.)
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    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!
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now