473,413 Members | 1,875 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,413 software developers and data experts.

Fully Qualified Class Name via Reflection - Namespace.Namspace.ClassName

Sorry for the crossposting guys. I figured this one might be a little
tricky, so I'm calling upon the C# brains out there to help out this poor VB
developer. I know enough C# to translate any code you can offer, if
necessary.

I have a very loosely coupled WinForms app written in VB.Net, Framework v1.1

I need to take a string value which contains the unqualified name of a
class, find the assembly that contains such a class, and instantiate the
class.

Here is my code to find the correct assembly.

Private Function GetAssembly(ByVal ForeignTable As String) As
Reflection.Assembly
Dim Assems() As Reflection.Assembly
Dim intLCV As Integer

Assems = AppDomain.CurrentDomain.GetAssemblies

For intLCV = 0 To Assems.Length - 1
If Not Assems(intLCV).GetType(ForeignTable, False, True) Is Nothing
Then
Return Assems(intLCV)
End If
Next

Return Nothing
End Function

It works fine, except my IF statement always returns Nothing because the
ForeignTable value is unqualified. If I hardcode it to
"BookWorks.InventoryBO.InventoryItems", it works just fine, but it fails on
"InventoryItems". It appears that I need find the namespace that covers the
assembly and concatenate that to ForeignTable. I can't find any
documentation on how to do this.

Any ideas?

Thanks everyone!
Nov 15 '05 #1
1 3201
Nevermind, I found a workaround. I added the following function and reworked
the GetAssembly() function to instantiate the return value.

Private Function AssemblyHasType(ByRef Assem As Reflection.Assembly,
ByVal ForeignTable As String) As String
Dim x As Type

For Each x In Assem.GetTypes
If x.Name = ForeignTable Then
Return x.FullName
End If
Next

Return ""
End Function

"Jeff Molby" <JeffMolby@C_mc_st.n_t> wrote in message
news:Oe**************@tk2msftngp13.phx.gbl...
Sorry for the crossposting guys. I figured this one might be a little
tricky, so I'm calling upon the C# brains out there to help out this poor VB developer. I know enough C# to translate any code you can offer, if
necessary.

I have a very loosely coupled WinForms app written in VB.Net, Framework v1.1
I need to take a string value which contains the unqualified name of a
class, find the assembly that contains such a class, and instantiate the
class.

Here is my code to find the correct assembly.

Private Function GetAssembly(ByVal ForeignTable As String) As
Reflection.Assembly
Dim Assems() As Reflection.Assembly
Dim intLCV As Integer

Assems = AppDomain.CurrentDomain.GetAssemblies

For intLCV = 0 To Assems.Length - 1
If Not Assems(intLCV).GetType(ForeignTable, False, True) Is Nothing Then
Return Assems(intLCV)
End If
Next

Return Nothing
End Function

It works fine, except my IF statement always returns Nothing because the
ForeignTable value is unqualified. If I hardcode it to
"BookWorks.InventoryBO.InventoryItems", it works just fine, but it fails on "InventoryItems". It appears that I need find the namespace that covers the assembly and concatenate that to ForeignTable. I can't find any
documentation on how to do this.

Any ideas?

Thanks everyone!

Nov 15 '05 #2

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

Similar topics

1
by: BH | last post by:
Is there a performance difference between importing (keyword "using") a namespace for an entire class file and using the classes from that namespace with the fully qualified name? Particularly...
3
by: Simon King | last post by:
I have created a service which uses the FileSystemWatcher to monitor folders for file changes. I have a app.config file which specifies which folders to watch and what to do when a change occurs. ...
5
by: fc2 | last post by:
Hi I have a problem with fully qualified names. According to the C# language specification: "Every namespace and type has a fully qualified name, which uniquely identifies the namespace or...
15
by: Mark Kamoski | last post by:
Hi Everyone-- Please help. How can one get the name of the current project and the current class? This is the situation. Suppose there is a project called "P1".
1
by: Jeff Molby | last post by:
Sorry for the crossposting guys. I figured this one might be a little tricky, so I'm calling upon the C# brains out there to help out this poor VB developer. I know enough C# to translate any code...
13
by: Brian | last post by:
I have many similar classes in a project, one for each type of report my app can create. I want to instantiate them based on a value passed in by a scheduler module. Right now I have Sub...
6
by: Rene Mansveld | last post by:
Hi, how can I create an instance (object) of a class (form) if I only know the classname (VB.NET 1.0)? I need to do this in a complex app where jobs consist of parts. Each part's data is saved...
1
by: Erland | last post by:
Hi all, As per my understanding in order to load an assembly using Assembly.Load() you have to provide fully qualified name of the assembly you are trying to load e.g. Assembly...
8
by: Jack | last post by:
Hi, I have a single class XXX residing in a namspace with the same name: XXX. I can access my class in my code just fine with: XXX.XXX.MySub() '(Note: shared sub!) But I don't want to...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
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...
0
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...
0
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...
0
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,...
0
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...

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.