473,396 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

create instance of class programmatically

I have a name of a class and the corresponding assembly.
Now I want to create an object of this class.
I think it is should work with Reflection. But I don't
know how exactly.

Could someone post a little sample in C# code.
Thanks in advance,
Bjoern

Nov 16 '05 #1
1 2422
Bjoern,

Assuming you have the full name of the assembly, you can do this:

// Load the assembly.
// You might need a different overload or method on Assembly to load the
assembly.
Assembly assembly = Assembly.Load(assemblyName);

// Get the type from the assembly.
Type type = assembly.GetType(typeName);

// Create an instance. You might need to call an overload that takes
parameters.
assembly.CreateInstance(type);

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Bjoern" <bj***********@web.de> wrote in message
news:10*********************@z14g2000cwz.googlegro ups.com...
I have a name of a class and the corresponding assembly.
Now I want to create an object of this class.
I think it is should work with Reflection. But I don't
know how exactly.

Could someone post a little sample in C# code.
Thanks in advance,
Bjoern

Nov 16 '05 #2

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

Similar topics

0
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a...
2
by: Serge Fournier | last post by:
Hello, I would like to create a MSDE instance at run time. (I know how to populate it with SQL file that I parse at run time). Is there any SQL or Transact SQL I could use ? Thanks for any...
4
by: Joe HM | last post by:
Hello - I have a Base Class where I want a New() implemented that can be called from the outside. This New() should create an instance of the appropriate cDerivedX Class ... The following...
12
by: Eric | last post by:
I have a custom component that can be dragged from the ToolBox onto a Windows Form (which means I can't modify it's constructor to add a name parameter). VS assigns it an instance name, but the...
9
by: John Salerno | last post by:
Let's pretend I'm creating an Employee class, which I will later subclass for more specific jobs. Each instance will have stuff like a name, title, degrees held, etc. etc. So I'm wondering, is...
2
by: Angel Of Death | last post by:
I have a method. It takes some XML as a parameter. Depending on the content of the XML it should create a specific object and call a KNOWN method. So: public void PersistXml(string XmlData){} ...
1
by: kimkamp | last post by:
I want to create a variable name programmatically. For instance: Dim GlobVar as String = "My.STL." Dim VarName as String = "sAccountNo" Dim VarValue as String = "ABC123" I want to end up...
13
by: miztaken | last post by:
Hi, My C# application have a following code to create an instance of Visual Studio. System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE. 8.0"); Object obj =...
6
by: Andy B | last post by:
I have the following schema. I need to know how to make an xml document based from it. The main worry I have is the DateTime field. <?xml version="1.0" encoding="utf-8"?> <xs:schema...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.