473,320 Members | 2,071 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,320 software developers and data experts.

abstract class, implementing virtual class loaded at runtime

I am trying to write several hardware interfaces that
would use the same base class and functions and be
implemented differently. I don't want to ship all of the
interfaces, but want to access them using the same generic
base class.

I have seen that I can use the Assembly.load method to
load the implementation I need for the hardware being
connected to, but wish to write the code such that I can
reference the methods of the class directly, and take
advantage of strong typing, etc. I don't see where using
dynamic loading of an assembly I can subsequently hook up
my strongly typed code to that assembly code.

Can I create this class from the loaded assembly and then
reference it using only the abstract class (eliminating
the requirement for the main compilation to know anything
about the derived class)?

The problem I am running into is how to allow the app to
switch between derived classes, without them all being
compiled in. Even the problem of instantiating them
correctly is befuddling me.

Here is an example:

namespace test
{
/// <summary>
/// base class for HW ctrl
/// </summary>
public class HWCtrl
{
public HWCtrl()
{

}

public virtual bool Run()
{
return true;
}
}
}

Now in a separate assembly:

namespace test
{
/// <summary>
/// derived class for HW ctrl
/// </summary>
public class DerivedHW : HWCtrl
{
public HWCtrl()
{

}

public bool Run()
{
return true;
}
}
}

I want to drop in the proper assembly for the job, and
bind to it at run time. Maybe this is easy, maybe it's not
possible, but I can't seem to find the answer in the
libraries or the web.

I have thought about using identical GUIDs for all the HW
implementations and creating a class interface, but that
seems to create its own problems.

Anyone been here before?

Thanks in advance,

Robb Sadler

Nov 15 '05 #1
2 7086
Robb Sadler <rs*****@mrgiga.com> wrote:

<snip>
I want to drop in the proper assembly for the job, and
bind to it at run time. Maybe this is easy, maybe it's not
possible, but I can't seem to find the answer in the
libraries or the web.


I *think* your question is answered in
http://www.pobox.com/~skeet/csharp/plugin.html
- which tries to answer a different question, but answers yours on the
way anyway. Try going through the example and see whether that does
what you need it to.

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

That was exactly what I was looking for. I was pretty sure
it could be done and looked in the MSDN for hours trying
to find the proper stuff to implement it. If I had known
to look for the keyword "CreateInstance" I would have been
all set as I found out with a quick search after the fact.

Many thanks, I have what I need.

Best regards,

Robb

I *think* your question is answered in
http://www.pobox.com/~skeet/csharp/plugin.html


Nov 15 '05 #3

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

Similar topics

10
by: Bjorn | last post by:
I'm using interfaces in C++ by declaring classes with only pure virtual methods. If then someone wants to implement the interface they needs to inherit from the class. If the implementing class...
33
by: Chris Capel | last post by:
What is the rationale behind the decision not to allow abstract static class members? It doesn't seem like it's a logically contradictory concept, or that the implementation would be difficult or...
6
by: Dan Sikorsky | last post by:
If we were to define all abstract methods in an abstract class, thereby making that class non-abstract, and then override the heretofore 'abstract' methods in a derived class, wouldn't that remove...
4
by: Rachel Devons | last post by:
All, I'm struggling with an OOP concept. Let me try to define what I'm wanting by using some classic examples. Let's say that I have classes called Square & Circle that derive from class...
7
by: jason | last post by:
In the microsoft starter kit Time Tracker application, the data access layer code consist of three cs files. DataAccessHelper.cs DataAcess.cs SQLDataAccessLayer.cs DataAcccessHelper appears...
2
by: talkingpidgin | last post by:
I am trying to figure out why it is not conventional to use protected constructors in abstract classes since the only time they should be called is by the constructors of it's derived classes. Is...
4
by: Arne Schmitz | last post by:
If i have an abstract base class, that only contains pure virtual methods (and maybe some non-virtual methods), is a vtable still being generated, for the first derived class that implements those...
4
by: David Zha0 | last post by:
Hi, "when we call a virtual method, the runtime will check the instance who called the method and then choose the suitable override method, this may causes the performance drop down", is this...
8
by: puzzlecracker | last post by:
0) What is the convention name for derived classes? 1) If we implement methods in abstract class, do we still need to declare them as abstract? 2) Are we allowed to override methods in derived...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.