473,804 Members | 2,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
"TestPlugin 1" and of course has the connect class in it. So I need the name
"TestPlugin1.Co nnect" 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("T estPlugin1.Conn ect")
dim o as Object Activator.Creat eInstance(ty)

or even

Dim plugIn As IPlugin =
DirectCast(objA ssembly.CreateI nstance("TestPl ugin1.Connect", False,
BindingFlags.Cr eateInstance, 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 1419
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("h olds information about loaded plugins")> _

Public Structure pluginInformati on

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(o bjAssembly.GetN ame.Name,
".Connect")

Dim plugIn As IPlugin = DirectCast(objA ssembly.CreateI nstance(classTo Use,
False, BindingFlags.Cr eateInstance, Nothing, aArgsList, Nothing, Nothing),
IPlugin)

'Dim plugIn As IPlugin = DirectCast(objA ssembly, IPlugin)

If plugIn Is Nothing Then

Throw New Exception("Fail ed to load plugin")

Else

Dim plugGUIDAttribu te As Attribute =
Attribute.GetCu stomAttribute(o bjAssembly.GetT ype(classToUse) ,
GetType(GuidAtt ribute))

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

Dim pInfo As New pluginInformati on

With pInfo

..Plugin = plugIn

..Name = DirectCast(plug In, IPlugin).name

..PluginGUID = plugGUID

End With

ht_loadedPlugin s.Add(pInfo.Plu ginGUID, pInfo)

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

plugIn.OnStartu p(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
5817
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 classes in different orders and there are times where I may add extra classes that weren't part of the original design. I'd like to be able to store a list of the classes, in the order that they are used, in a text file. Then I could have the first...
8
1644
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. Ultimately, I would need to loop through all of these, instantiating each of the classes in turn and calling a pre-known method of each. Finding the name of each module is not a problem, but loading the classes out the module once I know the name...
9
1656
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 applications need to serialise the classes to/from the same files but only the GUI app needs the full range of class methods. Now, the rendering app needs to be ported to multiple OS's but the GUI doesn't. In order to reduce the time/cost of porting I'd...
5
3503
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 too much overhead. The reason I'm doing this is because my system "rolls over" databases when it reaches the 2Gb limit with MSDE, but obviously I want to avoid this overhead if the user installs onto a full SQL server instance. Thanks
6
1584
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 are returned. For example, username dlozzi, password fun. It returns David Lozzi as full name. If I login as someone else on another computer, say username dsmith and password fun2, the second computer displays the correct fullname. HOWEVER if I...
0
3351
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 question.. The code fails with the error that: "Additional information: COM object that has been separated from its underlying RCW can not be used." if I make a call to pc.Count before iterating though the objects. Dim d As New...
5
1436
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 OOP using PHP's Classes. Seems quite handy so far, already generated a Login class and it does
0
1435
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 executing assembly, in which case you need to give assembly details as well. The line with testType2 is explicitly trying to find a class called "name". The string "name" and the variable called name are completely independent things.
45
3025
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 clsData Private m_objSQLClient As clsSQLClient Private m_objUsers As clsUsers
0
9715
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
9595
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,...
0
10603
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10356
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
10099
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
9176
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
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3003
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.