Say that I have a webpage called myPage which implement Page, but also implement my own interface called myInterface. My objective is to call a function called myFunction in myInterface with just the name of the class in string.
public interface MyInterfac{
Myfunction();
}
public partial class MyPage1: Page, MyInterface{
Myfunction(){ return "AAA"; }
}
public partial class MyPage2: Page, MyInterface{
Myfunction(){ return "BBB"; }
}
Now here is what information I have available to me:
string pageName1 = "MyPage1";
string pageName2 = "MyPage2";
How do get from here to something along the line of:
(MyInterface)MyPage1_instance.Myfunction(); //Should return AAA;
(MyInterface)MyPage2_instance.Myfunction(); //Should return BBB;
EDIT: Here is when I try to create an instance of MyInterface and it does not work:
Type myTypeObj = Type.GetType("MyPage1");
MyInterface MyPage1_instance = (MyInterface) Activator.CreateInstance (myTypeObj);