SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb Dynamicaly Loading Class

    Hi,

    I am programming an image library, and wanting to know how to load a class dynamically from a namespace (input would be string).

    i know you use the reflection namespace, but have had problems finding the correct functions. (Can only find how to load from a DLL file)

    Can anyone help on some insight?

    Beachnerd

  2. #2
    SitePoint Wizard
    Join Date
    Feb 2007
    Posts
    1,274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The System.Activator class, look it up on MSDN.

    Quick example:

    Code Csharp:
    MyClass mc = Activator.CreateInstance<MyClass>();

    or

    Code Csharp:
    MyInterface mi = (MyInterface)Activator.CreateInstance("assemblyname","typename");


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •