473,836 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fully Qualified Class Name via Reflection - Namespace.Namsp ace.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(ByV al ForeignTable As String) As
Reflection.Asse mbly
Dim Assems() As Reflection.Asse mbly
Dim intLCV As Integer

Assems = AppDomain.Curre ntDomain.GetAss emblies

For intLCV = 0 To Assems.Length - 1
If Not Assems(intLCV). GetType(Foreign Table, 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.Inve ntoryBO.Invento ryItems", 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 3229
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.Asse mbly,
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******** ******@tk2msftn gp13.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(ByV al ForeignTable As String) As
Reflection.Asse mbly
Dim Assems() As Reflection.Asse mbly
Dim intLCV As Integer

Assems = AppDomain.Curre ntDomain.GetAss emblies

For intLCV = 0 To Assems.Length - 1
If Not Assems(intLCV). GetType(Foreign Table, 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.Inve ntoryBO.Invento ryItems", 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
2027
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 when only one class from the namespace is needed once? For example: Option 1: ..... using System.Text; ...... StringBuilder sb = new StringBuilder();
3
4762
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. What I would like to do is specify a class and a method which can be invoked when that file change occurs. I can specify the name of the class/method in the config file but the app will see it as a string. Therefore my question is, can I...
5
3027
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 type amongst all others." However, I have problems compiling the following:
15
1996
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
2589
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 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...
13
2322
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 RunReports(sReport) Select Case sReport Case "CRByDistrict" oReport = New CRByDistrict
6
2439
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 in a separate database table. For the parts, the form's class name is saved in a data table, so that I know which form to use. As this is a string, I need to be able to create the form by it's name (like CreateObject() does for COM objects).
1
2330
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 asmb=Assembly.Load("System.Windows.Forms,Version=1.0.5000.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"); In this case i will have to provide the whole big string in
8
1900
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 clutter the code with the namespace every time I access my class.
0
9661
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
10831
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...
0
10536
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 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...
0
9367
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
7778
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 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...
0
6976
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5645
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...
2
4005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3108
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.