473,387 Members | 1,691 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,387 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 20 '05 #1
1 2566
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 20 '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...
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...
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. ...
4
by: Aashish Patil | last post by:
Hello, Is it possible to obtain the fully qualified name of a class in c#. What I am looking for is something analogous to Box.class.getName() that exists in Java. Its possible to get this by...
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".
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.