473,320 Members | 1,612 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.

Telling a classes full name

I am creating a plugin system and each plug-in has a class called "Connect",
which is what I created as the entry point for the plug-in. The problem is,
I need to get the Full type name of this to create a instance of it.
previously I was doing this a different name by using the same root
namespace name but different class names, but our new structure won't allow
for this, mainly because of possibly namespace naming conflicts between
plug-ins. So What I am doing is dynamically creating an instance of each
plug-in at load from the loaded assembly I created. But I can not figure out
how to instanciate the class now, because it needs to know what .NET
conciders the "root namespace" in the instanciation to instanciate the
class. For example one of my plug-in 's has the root namespace of
"TestPlugin1" and of course has the connect class in it. So I need the name
"TestPlugin1.Connect" to instanciate it as an object in memory. If I knew
how to get the full name like that I could easily do this.

Dim plugType as Type = Type.GetType("TestPlugin1.Connect")
dim o as Object Activator.CreateInstance(ty)

or even

Dim plugIn As IPlugin =
DirectCast(objAssembly.CreateInstance("TestPlugin1 .Connect", False,
BindingFlags.CreateInstance, Nothing, aArgsList, Nothing, Nothing), IPlugin)

but the problem is getting that full name. I can get the connect name, thats
simple its always the same... I just need the root namespace it's running
in, which is the problem... does anyone know how I can do this? thanks!
Nov 21 '05 #1
4 1398
Probably the simplest way would be to define a common interface that
all plugins must implement. Then it does not matter about root
namespaces and such since you will always instantiate the interface
which would not change.

Nov 21 '05 #2
and how would I go about doing that? because I've tried that before I think
and never got it to work right.

This is what I have now where IPlugin is the default plugin interface with
this definition..

Public Interface IPlugin

Sub OnBeginShutdown()

Sub OnStartup(ByVal Application As Object)

Sub OnConnect(ByVal application As Object, ByVal ConnectionMode As
ConnectionMode)

ReadOnly Property name() As String

ReadOnly Property GroupName() As String

ReadOnly Property Icon() As Drawing.Icon

ReadOnly Property Comments() As String

End Interface

<Description("holds information about loaded plugins")> _

Public Structure pluginInformation

Public Plugin As Object

Public Name As String

Public PluginGUID As Guid

End Structure
Dim objAssembly As [Assembly] = [Assembly].LoadFile(s)

Dim classToUse As String = String.Concat(objAssembly.GetName.Name,
".Connect")

Dim plugIn As IPlugin = DirectCast(objAssembly.CreateInstance(classToUse,
False, BindingFlags.CreateInstance, Nothing, aArgsList, Nothing, Nothing),
IPlugin)

'Dim plugIn As IPlugin = DirectCast(objAssembly, IPlugin)

If plugIn Is Nothing Then

Throw New Exception("Failed to load plugin")

Else

Dim plugGUIDAttribute As Attribute =
Attribute.GetCustomAttribute(objAssembly.GetType(c lassToUse),
GetType(GuidAttribute))

Dim plugGUID As New Guid(CType(plugGUIDAttribute, GuidAttribute).Value)

Dim pInfo As New pluginInformation

With pInfo

..Plugin = plugIn

..Name = DirectCast(plugIn, IPlugin).name

..PluginGUID = plugGUID

End With

ht_loadedPlugins.Add(pInfo.PluginGUID, pInfo)

Debug.WriteLine(String.Format("Loaded Plugin {0}, with GUID {1}",
pInfo.Name, pInfo.PluginGUID))

plugIn.OnStartup(AppObj)

End If
Nov 21 '05 #3
I am creating a plugin system and each plug-in has a class called "Connect",
which is what I created as the entry point for the plug-in. The problem is,
I need to get the Full type name of this to create a instance of it.


You could add an assembly-level attribute that holds the full name of
the plugin class.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #4
"Chris Dunaway" <du******@gmail.com> schrieb:
Probably the simplest way would be to define a common interface that
all plugins must implement. Then it does not matter about root
namespaces and such since you will always instantiate the interface
which would not change.


Sample:

<URL:http://dotnet.mvps.org/dotnet/samples/codingtechnique/PlugIns.zip>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #5

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

Similar topics

3
by: Hal Vaughan | last post by:
I'm not sure what the correct name for this would be. I'd think it's either an indirect reference, or a pointer, or something like that. I'm working on a program that would call a series of...
8
by: Rob Snyder | last post by:
Greetings - I have a situation where I need to be able to have a Python function that will take all the modules in a given directory and find all the classes defined in these modules by name....
9
by: Jack | last post by:
Hello I have a library of calculationally intensive classes that is used both by a GUI based authoring application and by a simpler non-interactive rendering application. Both of these...
5
by: Robin Tucker | last post by:
I'm looking for a simple way of telling (inside a stored procedure) if I'm currently using MSDE or a full SQL server. Ideally, there is some pre-defined environment variable that won't cause me...
6
by: David Lozzi | last post by:
Howdy, I'm new to classes. Below is my class User. (is this a reserved namespace or class?) It works great, kind of. If I specify the username and password, the correct firstname and lastname...
0
by: Ewart MacLucas | last post by:
generated some WMI managed classes using the downloadable extensions for vs2003 from mircrosoft downloads; wrote some test code to enumerate the physicall processors and it works a treat, but a...
5
by: Simon Dean | last post by:
Hello, Im hoping you can help me. Im, probably not that advanced with PHP, well, I probably am, but with a memory like a sieve, I rarely take in information... But, Im just considering some...
0
by: Jon Skeet [C# MVP] | last post by:
On Apr 11, 8:40 am, Andrew <And...@discussions.microsoft.comwrote: Okay, that means you've either not given the full classname (including namespace) or it's not in mscorlib or the currently...
45
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...
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...
0
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
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....

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.