473,796 Members | 2,741 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Instance a class at runtime

Hi

I need to instance a class at runtime, at runtime I can get the name in a
string, i would like to know if its possible to instance the class at
runtime with the name in a string.

Thanks for your assistance.

Ernesto Díaz
Feb 23 '06 #1
4 1244
You can get the Type using Type.GetType(st ring) and then you can use one of
the CreateInstance methods of the Activator class.
http://msdn.microsoft.com/library/de...ancetopic1.asp

--
Tim Wilson
..NET Compact Framework MVP

"Ernesto Díaz" <je****@vianney .com.mx> wrote in message
news:eP******** ******@TK2MSFTN GP12.phx.gbl...
Hi

I need to instance a class at runtime, at runtime I can get the name in a
string, i would like to know if its possible to instance the class at
runtime with the name in a string.

Thanks for your assistance.

Ernesto Díaz

Feb 23 '06 #2
Ernesto,
You can use the Activator.Creat eInstance or you can use reflection the get
the constructor and invoke it.
--

Stoitcho Goutsev (100)

"Ernesto Díaz" <je****@vianney .com.mx> wrote in message
news:eP******** ******@TK2MSFTN GP12.phx.gbl...
Hi

I need to instance a class at runtime, at runtime I can get the name in a
string, i would like to know if its possible to instance the class at
runtime with the name in a string.

Thanks for your assistance.

Ernesto Díaz

Feb 23 '06 #3
KH
See Assembly.GetTyp e() and Activator.Creat eInstance()
"Ernesto DÃ*az" wrote:
Hi

I need to instance a class at runtime, at runtime I can get the name in a
string, i would like to know if its possible to instance the class at
runtime with the name in a string.

Thanks for your assistance.

Ernesto DÃ*az

Feb 23 '06 #4
Does anybody have an example to help me understand ?

Thanks

Ernesto Díaz
Feb 23 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1179
by: Gunner | last post by:
I am trying to create a generic form driven the database. I want to be able to run create Crystal reports from this genric page and only want to have to enter some info in the database and drop the .RPT and .VB file of the report into a certain directory. My problem is how do I create an instance of a certain report at runtime. I will know the Class name from the VB file, but I do not know how or if I can create an instance of that class...
3
1422
by: Peter Oliphant | last post by:
Trying to save/load a class instance to a file is tough. The reason is because there is no way to preserve its type other than by conventon. For eample, one can save all the states of the members of a class instance to a file. But when loading it up the program can only read in the values stored. It has no idea what kind of class they came from, and there is no way to save info (that I'm aware of) that let can allow the application to...
3
1091
by: Ernesto Díaz | last post by:
Hi I need to instance a class at runtime, at runtime a can get the name in a string, i would like to know if its possible to instance the class at runtime with the name in a string. Thanks for your assistance. Ernesto Díaz
2
899
by: Ernesto Díaz | last post by:
Hi I need to instance a class at runtime, at runtime a can get the name in a string, i would like to know if its possible to instance the class at runtime with the name in a string. Thanks for your assistance. Ernesto Díaz
20
27800
by: Shawnk | last post by:
I would like to get the class INSTANCE name (not type name) of an 'object'. I can get the object (l_obj_ref.GetType()) and then get the (l_obj_typ.Name) for the class name. I there any way of getting 'l_Fred_my_ins' out of the following. .... My_cls l_Fred_my_ins = new My_cls();
2
2131
by: TEK | last post by:
Hello We're having a issue with a part of our app that is very strange, and I'm unable to see that it should be possible. We have: A collection (ActivityCollection) that is inherited from a general, abstract collection class that implements ITypedList and IBindingList When the program execute, the ITypedList.GetItemProperties method is
16
2706
by: alexia.bee | last post by:
Hi all, In some weird reason, excel instance won;t die if i remove the comment from 4 lines of setting values into struct. here is a snipcode public System.Collections.Generic.List<frmMain.sDBTest> LoadTestSet(string TestSetFile, System.Collections.Generic.List<frmMain.sDBTestDBviewList)
4
3968
by: =?Utf-8?B?SmFzb24gUmV5bm9sZHM=?= | last post by:
(using .net 2.0) Say you have a class structure like this: class Address .... end class class Person FirstName
45
3022
by: =?Utf-8?B?QmV0aA==?= | last post by:
Hello. I'm trying to find another way to share an instance of an object with other classes. I started by passing the instance to the other class's constructor, like this: Friend Class clsData Private m_objSQLClient As clsSQLClient Private m_objUsers As clsUsers
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10467
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10244
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10201
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.