basic reflection usages

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • puzzlecracker

    basic reflection usages

    Could someone provide an example or suggest tutorial whereby i can use
    reflection to create an object instance whose class implements certain
    interface.

    Here is what I have

    namespace MyFoo{
    internal interface IFoo{

    void Run(string [] args);

    }

    public class Bar:Foo{

    public Run(string []args ){}

    }

    class Test {

    static void Main(string[] args)
    {
    stirng className="Bar" ;
    //I want to create an instance of the class and call method Run

    }
    }

    Thanks
  • cfps.Christian

    #2
    Re: basic reflection usages

    if (obj is IFoo)
    ((IFoo)obj).Run (new string[] {"1", "2", "3"});

    If you must create the class by string name then you'll need to use
    Activator.Creat eInstance.

    Comment

    Working...