473,776 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do i create a components at runtime in C#


Hi,

My system uses Mail Client component
the Mail Client can either wrap exchange or pop3\SMTP server functions

in order to do that I declared an abstract named class MailClient
and create two components in two different DLL which derive from MailClient

ExchangeImpl.dl l
Pop3Impl.dll

In the server I define variable

MailClient mailClient;

Now I want to create a specific implementation according to configuration
or user choice

How do I create a specific mail client at run time?

Thanks.

Nov 22 '05 #1
4 4195
Julia <co********@012 .net.il> wrote:
My system uses Mail Client component
the Mail Client can either wrap exchange or pop3\SMTP server functions

in order to do that I declared an abstract named class MailClient
Where does this class live? It should be in another, separate DLL which
both ExchangeImpl and Pop3Impl reference.
and create two components in two different DLL which derive from MailClient

ExchangeImpl.dl l
Pop3Impl.dll

In the server I define variable

MailClient mailClient;

Now I want to create a specific implementation according to configuration
or user choice

How do I create a specific mail client at run time?


Load the appropriate assembly using Assembly.Load, get a reference to
the type itself using Assembly.GetTyp e, and then create an instance of
the type using Activator.Creat eInstance.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2
"Where does this class live? It should be in another, separate DLL which
both ExchangeImpl and Pop3Impl reference"

It does of course.

"Load the appropriate assembly using Assembly.Load, get a reference to
the type itself using Assembly.GetTyp e, and then create an instance of
the type using Activator.Creat eInstance."
Thanks.

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Julia <co********@012 .net.il> wrote:
My system uses Mail Client component
the Mail Client can either wrap exchange or pop3\SMTP server functions

in order to do that I declared an abstract named class MailClient


Where does this class live? It should be in another, separate DLL which
both ExchangeImpl and Pop3Impl reference.
and create two components in two different DLL which derive from MailClient
ExchangeImpl.dl l
Pop3Impl.dll

In the server I define variable

MailClient mailClient;

Now I want to create a specific implementation according to configuration or user choice

How do I create a specific mail client at run time?


Load the appropriate assembly using Assembly.Load, get a reference to
the type itself using Assembly.GetTyp e, and then create an instance of
the type using Activator.Creat eInstance.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 22 '05 #3
BTW can the name of the type which passed to GetType be the Base class name?

"Julia" <co********@012 .net.il> wrote in message
news:u$******** ******@TK2MSFTN GP11.phx.gbl...
"Where does this class live? It should be in another, separate DLL which
both ExchangeImpl and Pop3Impl reference"

It does of course.

"Load the appropriate assembly using Assembly.Load, get a reference to
the type itself using Assembly.GetTyp e, and then create an instance of
the type using Activator.Creat eInstance."
Thanks.

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Julia <co********@012 .net.il> wrote:
My system uses Mail Client component
the Mail Client can either wrap exchange or pop3\SMTP server functions

in order to do that I declared an abstract named class MailClient


Where does this class live? It should be in another, separate DLL which
both ExchangeImpl and Pop3Impl reference.
and create two components in two different DLL which derive from MailClient
ExchangeImpl.dl l
Pop3Impl.dll

In the server I define variable

MailClient mailClient;

Now I want to create a specific implementation according to configuration or user choice

How do I create a specific mail client at run time?


Load the appropriate assembly using Assembly.Load, get a reference to
the type itself using Assembly.GetTyp e, and then create an instance of
the type using Activator.Creat eInstance.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 22 '05 #4
Julia <co********@012 .net.il> wrote:
BTW can the name of the type which passed to GetType be the Base
class name?


Well, that would return the base type rather than the actual type, so
when you then called Activator.Creat eInstance it would create an
instance of that base type (if it could). How would it know which
derived type to construct?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #5

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

Similar topics

0
1942
by: Timothy | last post by:
I have developed an application that uses the Office Web Components 2003. This application will be deployed to systems that do not have Office or the Web Components installed. The problem that I am encountering is that if the client does not have Office or the Web Components installed, it produces a System.Runtime.InteropServices.COMException error. I believe what is happening is that all the necessary files needed to use the Web Components...
4
365
by: Julia | last post by:
Hi, My system uses Mail Client component the Mail Client can either wrap exchange or pop3\SMTP server functions in order to do that I declared an abstract named class MailClient and create two components in two different DLL which derive from MailClient ExchangeImpl.dll Pop3Impl.dll
8
6948
by: Larry__Weiss | last post by:
What kind of licensing is needed to be able to use the Microsoft Access product and distribute the applications? In other words, what version of Microsoft Access does a developer need to buy in order to allow distribution of the runtime components without incurring any additional license fees per installation of the runtime? Has this changed very much over the versions of MS Access (especially since Access 2.0)? - Larry Weiss
2
30164
by: Dennis C. Drumm | last post by:
This is a restatement of an earlier post that evidently wasn't clear. I am building a custom MessageBox dialog that has, among other things, a few new button options (yes to all, no to all, etc.) and would like to make the dialog look and act like the standard MessageBox. Therefore, I would like to put in the message section the same type of icons found in the MessageBox dialog, such as MessageBoxIcon.Exclamation. In another post here I had...
9
6525
by: S Wheeler | last post by:
Hi all - I am trying to create an instance of a vb .net class containing a form from unmanaged vc++. The vb.net is a dll. How to do this ? I am trying #import by can't seem to get it quite right. I suspect this is quite simple though. Thanks in advance...
1
1288
by: Wilson | last post by:
Hi, How can I get the list of web components in the page at runtime ? e.g. there is two components in the page : 1. label1 2. textbox1 I want to just the list of the above components.
8
1756
by: Claus | last post by:
Hi all, I am new to C#, .NET and Visual Studio but I have been coding professionally for more than 10 years, so I am not a complete newbe :-) At my work we are now in the process of switching from Borland Delphi to Visual Studio and C#. We have a lot of applications that we do not have time to recode to .NET, so we are planning to do all "new" developments in C#. And this is where my question pop up:
9
2539
by: Laurence | last post by:
Hi there, I have already checked the URL http://www-306.ibm.com/software/data/db2/9/sysreqs.html. There are no Operating System need to install C rumtime environment components other than AIX before installing DB2 Server product. Is it specific for AIX only? By the way, the sentence "If you are installing the Application Development Client, you must have a C compiler to build SQL Stored Procedures". Does it mean for HP-UX and Solaris...
18
2297
by: Angus | last post by:
Hello We have a lot of C++ code. And we need to now create a library which can be used from C and C++. Given that we have a lot of C++ code using classes how can we 'hide' the fact that it is C++ from C compilers? Can we have a C header file which uses the functionality of the C++ files and compile this into a lib file?
0
9627
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
9462
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10060
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
9922
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8951
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
7469
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
6721
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
5367
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...
0
5492
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.