DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2007

    Convert String to type via the string

    This is what I have.

    String TypeName; //This is passed in from the webPage.
    Type objectType = typeof(TOG.PJM.Entities.Nodes);
    //Type objectType = Type.GetType(TypeName);
    _objectGraph = Activator.CreateInstance(objectType);
    return _objectGraph;

    I have two seperate projects and namespaces that seperate the Class that I'm tring to pull the type of and this method that returns the type of the class in the other project/namespace. The only thing I have is the string TypeName which contains "TOG.PJM.Entites.Nodes, TOG.PJM". You can see that I use that in the commented out line, and that's what I want, but unless I use the typeof first it acts as if it can't see the Nodes class. But if I have the typeof first, as I do here and I uncommented out that line, it would work just fine.

    Sorry if this is confusing.

    Thanks for any suggestions.

  2. #2
    Join Date
    Nov 2003
    Portland, OR
    Why not use the overload of CreateInstance that accepts the type name as a string? http://msdn2.microsoft.com/en-us/lib...a4(VS.80).aspx
    Phil Weber

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Similar Threads

  1. App Object
    By Rob Teixeira in forum .NET
    Replies: 15
    Last Post: 05-31-2002, 03:30 PM
  2. Writing in HKEY_LOCAL_MACHINE...Access is denied
    By Martin in forum VB Classic
    Replies: 22
    Last Post: 12-03-2001, 03:53 AM
  3. How do I detect an FTP timeout?
    By Julian Milano in forum VB Classic
    Replies: 0
    Last Post: 08-10-2000, 09:16 PM
  4. Deadlock error.. how to remove
    By Chandra in forum VB Classic
    Replies: 0
    Last Post: 06-22-2000, 12:52 PM
  5. Database problems
    By Robert Rieth in forum VB Classic
    Replies: 1
    Last Post: 04-11-2000, 03:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.