Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / November 2003

Tip: Looking for answers? Try searching our database.

Listing .net data types

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
steve bugden - 05 Nov 2003 13:04 GMT
I'm trying to obtain a list of all available data types
for a given assembly/namespace, i.e. the same list that
would be displayed by the intellisense when typing: "dim
str as " in a vb function.

I have tried the following code:

    Public Function GetAssemblysTypes(ByVal
vstrAssemblyPath As String, ByVal vstrNameSpace As String)
As Type()

        'Get the dll/exes assemby
        Dim objassembly As
System.Reflection.Assembly =
System.Reflection.Assembly.LoadFrom(vstrAssemblyPath)
        Dim objAssemblyName As
System.Reflection.AssemblyName
        'Dimension an array list to
        Dim arr As New ArrayList()
        Dim objType As Type
        Dim i As Integer

        objAssemblyName = objassembly.GetName

        'have we found the namespace?
        If objAssemblyName.Name = vstrNameSpace
Then
            'Write out the assembly's type info
            Return objassembly.GetTypes()
        End If

        'Get the referenced assemblies
        Dim objReferencedAssemblies() As
System.Reflection.AssemblyName =
objassembly.GetReferencedAssemblies()
        'Determine how many assemblies there are
        Dim intCount As Integer = UBound
(objReferencedAssemblies, 1)

        'Loop through each assembly
        For i = 0 To intCount - 1

            Try

                'Get the next assembly
                objAssemblyName =
objReferencedAssemblies(i)

                If vstrNameSpace =
objAssemblyName.Name Then

                    'Load the assembly
                    objassembly =
System.Reflection.Assembly.Load(objAssemblyName)
                    Return
objassembly.GetTypes
                End If

            Catch ex As Exception
                'MsgBox(ex.Message)
            End Try

        Next

    End Function

    Public Function GetAssemblysNamespaceList(ByVal
vstrAssemblyPath As String) As String()

        'Get the dll/exes assemby
        Dim objassembly As
System.Reflection.Assembly =
System.Reflection.Assembly.LoadFrom(vstrAssemblyPath)
        Dim objAssemblyName As
System.Reflection.AssemblyName

        'Dimension an array list to
        Dim arr(0) As String
        Dim objType As Type
        Dim i As Integer

        objAssemblyName = objassembly.GetName
        arr(0) = objAssemblyName.Name

        'Get the referenced assemblies
        Dim objReferencedAssemblies() As
System.Reflection.AssemblyName =
objassembly.GetReferencedAssemblies()

        'Determine how many assemblies there are
        Dim intCount As Integer = UBound
(objReferencedAssemblies, 1)

        ReDim Preserve arr(intCount)

        'Loop through each assembly
        For i = 1 To intCount - 1
            Try
                'Get the next assembly
                objAssemblyName =
objReferencedAssemblies(i)
                arr(i) =
objAssemblyName.Name
            Catch ex As Exception
                'MsgBox(ex.Message)
            End Try
        Next

        Return arr

    End Function
'*******************************************************
GetAssemblysNamespaceList retrieves a list of namespaces
for a given assembly (specified by path/filename).
GetAssemblysTypes retrieves the data types for a namespace
(i.e. System) in an assembly specified by path/filename.
So I use GetAssemblysNamespaceList to populate a combo and
GetAssemblysTypes to populate a grid.
The problems are:

1)The list is not the same as given when coding within the
function.
2) The types String, Int16, Int32, are not displayed in
the System namespace.
3) I am also getting an error trying to read a referenced
assembly, a dll which I have written, although an upto
date version is present exactly as referenced in the
Reference properties path.

Any help greatly appreciated.

Steve
Rahul Kapoor - 06 Nov 2003 00:58 GMT
what assembly name are you using to list Int32 etc, mscorlib.dll or
system.dll

Rahul
r_ahu_l@nospam.yahoo.com

> I'm trying to obtain a list of all available data types
> for a given assembly/namespace, i.e. the same list that
[quoted text clipped - 128 lines]
>
> Steve
Steve Bugden - 08 Nov 2003 10:19 GMT
Rahul,

Thanks for your reply and sorry for my delay in replying,
I have been away.

The system namespace is picked up by my code as a
referenced namespace but MSCORLIB isn't. I've just tried
displaying it's types to see that int32 etc are displayed.
So I can add mscorlib.dll explicitly to the list of
referenced assemblies to get what I want, I assume it is
not shown in the referenced assemblies list as it is so
core.

Steve.

>-----Original Message-----
>what assembly name are you using to list Int32 etc, mscorlib.dll or
[quoted text clipped - 137 lines]
>
>.
Sebastien Lambla - 11 Nov 2003 15:30 GMT
A few notes

* When you load an Assembly and the Type, all this code will stay in your
process memory forever, untill you shut down. Might be worthwhile to do the
extracting in a separate application domain, and just get the bits you want
as strings back into your application.

* When you use LoadFrom, you are changing the way the Fusion Loader works,
and you are changing the context in which they are loaded. So when you're
calling Load from the referenced list you probe, the fusion loader is going
to look inside the path of the host application doing the probing, and might
not be able to find the dlls. Use the Fusion log viewer to see how it is
influenced when probing for referenced assemblies. Eventually, either always
use LoadFrom, or load them in a separate AppDomain by setting the path to
the one you loaded your assembly from.

* mscorlib is a special case, you can't load it by way of managed code. You
can still access the currently loaded assembly by the mean of (sorry for the
c# code) typeof(int).Module.Assembly

Finally, don't forget that some namespaces are implemented in several dlls,
so you will have to load mscorlib.dll and System.dll to get a view of the
whole namespace.

As for members, could you show an example?

Signature

Sebastien Lambla
http://thetechnologist.is-a-geek.com/blog/

> Rahul,
>
[quoted text clipped - 161 lines]
> >
> >.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.