How to input class name by user?
-
Hi! I am making Linqtosql application in which classes are used in mapping of database. I want to let the user input the class name from interface(windows form) for e.g if Class name = hello its object declaration is e.g hello object = new hello() now in this I want the user to enter the class name "hello" i tried storing user input in a string , but doesnt work , what to do?
-
Hi! I am making Linqtosql application in which classes are used in mapping of database. I want to let the user input the class name from interface(windows form) for e.g if Class name = hello its object declaration is e.g hello object = new hello() now in this I want the user to enter the class name "hello" i tried storing user input in a string , but doesnt work , what to do?
Use reflections in C# with reflections u can store the class name in a string and then create the object of that class at run time Click Here:cool:
modified on Wednesday, May 4, 2011 1:48 AM
-
Use reflections in C# with reflections u can store the class name in a string and then create the object of that class at run time Click Here:cool:
modified on Wednesday, May 4, 2011 1:48 AM
I couldn't understand the tutorial.. plz just in simple explanation , tell that how can i store a class name in string format? I have a class let say ABC let say it has fields. class abc { int a; int b; } now if i want to make an object of abc in an another class, through user entering the class name , how to do using reflections? I am sure it is just 2 lines of code :)
-
I couldn't understand the tutorial.. plz just in simple explanation , tell that how can i store a class name in string format? I have a class let say ABC let say it has fields. class abc { int a; int b; } now if i want to make an object of abc in an another class, through user entering the class name , how to do using reflections? I am sure it is just 2 lines of code :)
Type type = Type.GetType("abc");
object obj = Activator.CreateInstance(type);pass the class name in the GetType function if the class has a namespace pass it with the namespace.classname rate me if this post was helpful
modified on Monday, May 9, 2011 6:51 AM
-
Type type = Type.GetType("abc");
object obj = Activator.CreateInstance(type);pass the class name in the GetType function if the class has a namespace pass it with the namespace.classname rate me if this post was helpful
modified on Monday, May 9, 2011 6:51 AM
i tried it. I had the namespace FYP_RFID and class name RECORDS. Type type = Type.GetType("FYP_RFID.RECORDS"); object obj = Activator.CreateInstance(type); BUT when i try to acces any member uding obj. nothing happens but when i manually make the object like RECORDS OBJ = NEW RECORDS(); THEN through obj. function i can acess the members of class. what could be the problem? (I appreciate you helping me out:) )
-
i tried it. I had the namespace FYP_RFID and class name RECORDS. Type type = Type.GetType("FYP_RFID.RECORDS"); object obj = Activator.CreateInstance(type); BUT when i try to acces any member uding obj. nothing happens but when i manually make the object like RECORDS OBJ = NEW RECORDS(); THEN through obj. function i can acess the members of class. what could be the problem? (I appreciate you helping me out:) )
There is a class called MethodInfo where in you will get all the info of the methods in the object and i would suggest you to learn this from any forums because it would help you more to learn about it like we could only guide you how to do a particular thing it would be good for you to learn new things