In VB6, we created a number of ActiveX DLLs that all shared a similar
interface. The main application would load these in dynamically (late-bound.)
This worked well for our situation because we could update the DLLs
independently of the main EXE, and performance was not a problem.
We want to do the same thing in C# (at least test it), but we are not
exactly clear what the best practice is. We would prefer to do something
similar, but we are open to any advice.
In VB6 terms, we have a shared class which serves as the interface to our
DLLs. To keep the example simple, I created this:
‘ VB6 Class Interface
Public Function DoSomething() As Boolean
DoSomething = True
End Function
Each DLL would be compiled with the same class.
A simple example of how we would use this is here:
Private Sub Command1_Click( )
Dim objClass As Object
Dim strClass As String
Dim bUseFirstClass As Boolean
bUseFirstClass = False
If bUseFirstClass = True Then
strClass = "prjTestA.clsEx ample"
Else
strClass = "prjTestB.clsEx ample"
End If
Set objClass = CreateObject(st rClass)
Debug.Print objClass.DoSome thing()
Set objClass = Nothing
End Sub
What is the best way to do something similar in C#? We started looking at
reflection, but I want to make sure that is considered the best way to
approach this, or if there is some other words of wisdom we should follow.
Any sample code would be most appreciated!
Thank you for your time and advice.
Mo 4 2891
In C#, you could have (converted directly via Instant C#):
private void Command1_Click( )
{
object objClass = null;
string strClass = null;
bool bUseFirstClass = false;
bUseFirstClass = false;
if (bUseFirstClass )
{
strClass = "prjTestA.clsEx ample";
}
else
{
strClass = "prjTestB.clsEx ample";
}
System.Type objClassType = System.Type.Get TypeFromProgID( strClass);
objClass = System.Activato r.CreateInstanc e(objClassType) ;
Debug.Print objClassType.In vokeMember("DoS omething",
System.Reflecti on.BindingFlags .InvokeMethod, null, objClass, null);
objClass = null;
}
--
David Anton www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
"moflaherty " wrote:
In VB6, we created a number of ActiveX DLLs that all shared a similar
interface. The main application would load these in dynamically (late-bound.)
This worked well for our situation because we could update the DLLs
independently of the main EXE, and performance was not a problem.
We want to do the same thing in C# (at least test it), but we are not
exactly clear what the best practice is. We would prefer to do something
similar, but we are open to any advice.
In VB6 terms, we have a shared class which serves as the interface to our
DLLs. To keep the example simple, I created this:
‘ VB6 Class Interface
Public Function DoSomething() As Boolean
DoSomething = True
End Function
Each DLL would be compiled with the same class.
A simple example of how we would use this is here:
Private Sub Command1_Click( )
Dim objClass As Object
Dim strClass As String
Dim bUseFirstClass As Boolean
bUseFirstClass = False
If bUseFirstClass = True Then
strClass = "prjTestA.clsEx ample"
Else
strClass = "prjTestB.clsEx ample"
End If
Set objClass = CreateObject(st rClass)
Debug.Print objClass.DoSome thing()
Set objClass = Nothing
End Sub
What is the best way to do something similar in C#? We started looking at
reflection, but I want to make sure that is considered the best way to
approach this, or if there is some other words of wisdom we should follow.
Any sample code would be most appreciated!
Thank you for your time and advice.
Mo
"moflaherty " <mo********@dis cussions.micros oft.comwrote in message
news:3E******** *************** ***********@mic rosoft.com...
In VB6, we created a number of ActiveX DLLs that all shared a similar
interface. The main application would load these in dynamically
(late-bound.)
This worked well for our situation because we could update the DLLs
independently of the main EXE, and performance was not a problem.
We want to do the same thing in C# (at least test it), but we are not
exactly clear what the best practice is. We would prefer to do something
similar, but we are open to any advice.
In VB6 terms, we have a shared class which serves as the interface to our
DLLs. To keep the example simple, I created this:
' VB6 Class Interface
Public Function DoSomething() As Boolean
DoSomething = True
End Function
Each DLL would be compiled with the same class.
A simple example of how we would use this is here:
Private Sub Command1_Click( )
Dim objClass As Object
Dim strClass As String
Dim bUseFirstClass As Boolean
bUseFirstClass = False
If bUseFirstClass = True Then
strClass = "prjTestA.clsEx ample"
Else
strClass = "prjTestB.clsEx ample"
End If
Set objClass = CreateObject(st rClass)
Debug.Print objClass.DoSome thing()
Set objClass = Nothing
End Sub
What is the best way to do something similar in C#? We started looking at
reflection, but I want to make sure that is considered the best way to
approach this, or if there is some other words of wisdom we should follow.
Any sample code would be most appreciated!
Thank you for your time and advice.
Mo
I think I know what you are trying to do but I'm not sure. In VB6, you
didn't have proper inheritance, but in C#, you do. There is no reason you
cannot create an interface directly. In C#, you can create the interface,
compile it into a DLL, and then simply make a reference to that DLL from all
projects that need to implement the interface (no need to compile the
'psuedo-base-class' into every DLL... it's a real base class or interface
now).
So all the design patterns work just fine in C#. Examples of how to use
each of the design patterns in C# can be found at www.dofactory.com
For what you are trying to do, you are creating a plug in. So create the
interface that all of your subtypes will implement and create a factory that
is able to instantiate a type based on a string. The string can come from
reflection or it can come from a config file... either way, hide the
creation of your plug-in type in a factory method so that the calling code
won't have to know or care where your logic is for discovering the actual
type you are creating.
I hope that helps,
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
On Jan 31, 10:25 am, moflaherty <moflahe...@dis cussions.micros oft.com>
wrote:
In VB6, we created a number of ActiveX DLLs that all shared a similar
interface. The main application would load these in dynamically (late-bound.)
This worked well for our situation because we could update the DLLs
independently of the main EXE, and performance was not a problem.
We want to do the same thing in C# (at least test it), but we are not
exactly clear what the best practice is. We would prefer to do something
similar, but we are open to any advice.
In VB6 terms, we have a shared class which serves as the interface to our
DLLs. To keep the example simple, I created this:
' VB6 Class Interface
Public Function DoSomething() As Boolean
DoSomething = True
End Function
Each DLL would be compiled with the same class.
A simple example of how we would use this is here:
Private Sub Command1_Click( )
Dim objClass As Object
Dim strClass As String
Dim bUseFirstClass As Boolean
bUseFirstClass = False
If bUseFirstClass = True Then
strClass = "prjTestA.clsEx ample"
Else
strClass = "prjTestB.clsEx ample"
End If
Set objClass = CreateObject(st rClass)
Debug.Print objClass.DoSome thing()
Set objClass = Nothing
End Sub
What is the best way to do something similar in C#? We started looking at
reflection, but I want to make sure that is considered the best way to
approach this, or if there is some other words of wisdom we should follow.
Any sample code would be most appreciated!
Thank you for your time and advice.
Mo
You didn't use an interface at all, except only superficially.
Otherwise your classes would have used the Implements keyword to
implement the interface. If you had used a "real" interface, you
would not have had to use a variable of type Object, but a variable of
the type of the interface class.
But as Nick Malik said, in C#, you can create a proper Interface type
and then implement it any classes you needed. You can use reflection
to check to see if a class implements the interface and instantiate it
if it does.
Chris This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David Noble |
last post by:
We've been developing a web site using 3-tier architecture for 18
months now.
There is a common layer that defines the classes - using XML schemas.
The data layer acts as a wrapper to 3 databases - SQL Server, Oracle
and AS400.
The business layer exposes web services which communicate with the
front end, ASP.Net. All 3 tiers are on different boxes. This works
well.
Now I am leading a team to build a winforms app. I need some advice as
|
by: Matt Kruse |
last post by:
http://www.JavascriptToolbox.com/bestpractices/
I started writing this up as a guide for some people who were looking for
general tips on how to do things the 'right way' with Javascript. Their code
was littered with document.all and eval, for example, and I wanted to create
a practical list of best practices that they could easily put to use.
The above URL is version 1.0 (draft) that resulted. IMO, it is not a
replacement for the FAQ,...
|
by: laimis |
last post by:
Hey guys,
I just recently got introduced to data mappers (DTO mapper). So now I
have a SqlHelper being used by DTOMapper and then business layer is
using DTOMapper when it needs to persist object to database or load them
back. Everything is working nicely so far. My question is, is it OK
practice to use DTOMapper rfom the presentation layer? For instance, if
I want to present in HTML format the list of entries in my database,
should I...
|
by: mikelinyoho |
last post by:
Does the following program architecture make sense?
#include <stdio.h>
#include "test1.c"
#include "sample.cpp"
int main(void){
output();
|
by: carsonbj |
last post by:
I have an issue where the below operation works on a little-endian
architecture but not on a big-endian architecture. I was under the
impression that pointer arithmetic is architecture independant and
bitwise operations are architecture dependant. The intention is to
store two bytes, as chars, extracted from a short input parameter as:
<code>
void foo(short id_pair)
{
char *ptr = &id_pair;
| |
by: crm-tutorial |
last post by:
Service-Oriented Architecture(SOA) - Principles & Practice (October
2006)
The Principles of SOA,Loosely-Coupled Architecture,The SOA Solution -
How it Works,The iBOLT Flow Editor, Composite Applications,Implementing
a SOA with iBOLT
http://flying-rugs.com/soa
|
by: Jon |
last post by:
I'm working on a project and the lead developer wants to put all of the
business logic on the database side. He wants the proc to do all of the
logic and create XML on the fly, parse out data, etc, and then return the
final result to the business layer. I pushed back and said that the business
layer should do all of the logic, just have SQL return the data needed and
then have the code do all of the XML creation, parsing of data, etc. I was...
|
by: anthonykallay |
last post by:
Hi there,
I am building a website for a group that has 4 companies under it. The
sites are fairly similar so i want to be able to use the same set of
code in the App_Code folder.. I also want to share controls between
the sites. What i am after is a bit of advice as to best practice to
achieve this. Obviously this seems to be a good use of themes so i
will do this to use diffrerent colours where appropriate.. My main
concern is how to...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |